Exit application in iOS 4.0
Also see iOS Debugging Magic (Technical Note TN2239):
Be 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
There's a reason for programmatically invoked exit()
.
Suppose you have a voip app that is always started at boot and restarted when killed by the system e.g. when memory warning happens. Normally it's preferred behavior because you need to run in background in order to maintain your voip TCP sockets.
However, if the app supports multiple modes of operation — like a) run in background using TCP, and b) do not run in background but start only after accepting PUSH notification —, if the user uses the app in b) mode he doesn't fancy that the app is consuming memory that can be used for other apps.
So it would be nice if the app could check upon the start if it was started to the background and user wanted the app to run in b) mode and gracefully exit(0)
so it's no longer automatically restarted.
You can set the Info.plist key UIApplicationExitsOnSuspend to make sure the app is completely terminated.
No still shouldn't do this.
You 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.