Before iOS4.0 clicking the home button on iPhone exits the application, and Apple had in their guide that programmatically exiting the application was not accepted.
now everything changed in iOS4.0, clicking the home button puts your app in a suspended mode (multitasking).. and I think there should be a clear way for the user to exit the app, like an exit button.
is it now OK with apple? and how can it be done?
No still shouldn't do this.
ReplyDeleteYou have handlers for the different stages, so this is how you should do it. There's no point in exiting manually. If you restart the app, ideally it would start where you left off, so this is either by resuming or by starting and loading the old state.
No reason for exit.
Edit
As this keeps popping up again: iOS Human Interface Guidelines says "Don't Quit Programmatically". And we have seen many reports of apps that had calls to exit() in them in the past.
Exiting instead of suspending by setting the appropriate key in the Info.plist file is perfectly fine, of course - but that's not a dedicated UI Button, just application-specific implementation of program exit by the home button.
You can set the Info.plist key UIApplicationExitsOnSuspend to make sure the app is completely terminated.
ReplyDeleteI had a real problem with this. There is a big point in exiting manually or prgramatically.
ReplyDeleteWith previous iPhone OS, my app was writing out its state (first use or second time onwards, etc.) in a plist when it terminated. When the user came back, it wanted to show different things by reading the plist. Also, it wanted to show the first screen every time when the user came back after exiting.
With app becoming suspended in the background with iPhone OS4, the app comes back where it left off (i.e. showing the same screen wherever the user was on) and never changes the state of it, because applicationWillTerminate is now never called.
Becasue this is the behaviour desired most of the time (to be able to continue when you step out of the app temporary), there has to be a way to be able to choose, i.e. suspend it or quit.
Since setting the UIApplicationExitsOnSuspend=YES gives only one way (i.e. it always terminates when the HOME is pressed), this is not a solution I am looking for.
I want the app to know once the whole chain of steps are completed, opposed to just the sequence was suspended, and to quit itself at the right time.
To do this, I have to be able to terminate the app and write out the state once the use completed the entire sequence. Other times, I just want the app to be suspended.
If you tap the HOME button twice you can see the suspended apps. I can delete (quit) my app by touching it longer and touch the (-) symbol that comes up, but this is not so intuitive for the users and too many steps.
Another option is to have a Quit button as one of the Nav Tabs in my app, but that is ugly. For now, my only option seems to be opting to set the UIApplicationExitsOnSuspend=YES.
Also see iOS Debugging Magic (Technical Note TN2239):
ReplyDeleteBe mindful that the iOS application lifecycle is under user control, meaning that iOS applications should not just quit. Your release build should only call abort in circumstances where it would have crashed anyway, and the abort call prevents damage to user data or allows you to more easily diagnose the problem.
While on the topic of determining the cause for premature exit, Understanding and Analyzing iPhone OS Application Crash Reports (Technical Note TN2151) might be of interest.
Sorry for going off topic a bit, but it relates to early exits and diagnosis.
Jeff
You can put an app programatically in background with this private command :
ReplyDelete[[UIApplication sharedApplication] suspend];
You can always use exit(1). This is a raw/forced exit with an integer for a code/reason.
ReplyDeleteYou can used this during development, like in simulation mode when you just want to terminate; as in NOW.