Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Effects of iPhone home button to app
-
If I have some simple code that displays "hello world" in a label with a button push, we know that that text will remain there. Normally if you press the home button and then come back to the app the text should still be there. However, I am finding when running the app in Xcode that when I return the text is cleared. Basically the app runs from a fresh start when i return.
Why does this do this and how do I fix it? I have written apps in Xcode using Objective-C and it automatically remembers the app state when I return.
-
The Xcode template checks if the script is still running when you press the home button – if it isn't, it basically calls
exit(0)
. The intention is to make restarting a script easier and to save some memory. If you don't want that, you could put something liketime.sleep(10**7)
at the end of your script. -
Just an interesting side question - how expensive, cpu-wise, is a running script while it's "sleeping?"
-
@donnieh I have to correct myself. What I described above used to be the case, but I've changed it in the 1.6-based template that you're probably using.
You can change the behavior of the home button there by editing the "Info.plist" file that you'll find in the project. Simply select "NO" for the "Application does not run in background" setting (or delete the entire row, which is equivalent). Depending on your Xcode settings, you may see "UIApplicationExitsOnSuspend" as the setting name.
-
Great! Thank you! I have to say that almost anyone making an iPhone app with Pythonista would run into this and would desire a solution.
-
This post is deleted!