How do I programmatically quit my iOS application?
Q: How do I programmatically quit my iOS application?
A: There is no API provided for gracefully terminating an iOS application.
In iOS, the user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take — turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.
Additionally, data may not be saved, because
-applicationWillTerminate: and similar
UIApplicationDelegate methods will not be invoked if you call
If during development or testing it is necessary to terminate your application, the
abort function, or
assert macro is recommended.
Document Revision History
Updated to more strongly discourage the exit function, and include best practices for debugging.
New document that discusses best practices for terminating an iOS application in code.