How do I programmatically quit my iOS application?

来源:互联网 发布:家庭网络布线工 编辑:程序博客网 时间:2024/06/05 23:54

[https://developer.apple.com/library/content/qa/qa1561/_index.html]

Technical Q&A QA1561

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.

Warning: Do not call the exit function. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen.

Additionally, data may not be saved, because -applicationWillTerminate: and similar UIApplicationDelegate methods will not be invoked if you call exit.

If during development or testing it is necessary to terminate your application, the abort function, or assert macro is recommended.


0 0