[https://developer.apple.com/library/content/qa/qa1561/_index.html]
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.
本文解答了如何在iOS中程序化地退出应用的问题。指出iOS应用不应主动调用退出方法,而应通过显示警告来提示用户解决应用无法正常运行的问题,并让用户自行决定是否退出。文章还警告不要使用exit函数,因为它会导致应用看起来像是崩溃而非优雅地退出。
347

被折叠的 条评论
为什么被折叠?



