如何防止我的应用程序在iPhone上的后台运行 [英] How to prevent my app from running in the background on the iPhone
问题描述
当按下主页按钮时,有没有办法让应用程序退出而不是转到后台?出于安全原因,如果应用程序不在后台运行但在推送主页时实际关闭会更好。这对于用户的安全性而言不,而是针对应用上的公司数据,因此不是用户的选择。除了强行退出之外,我找不到任何办法退出,苹果不鼓励。
Is there any way to cause an app to quit instead of going to background when the home button is pressed? For security reasons, it would be better if the app did not run in background but actually closed when home is pushed. This is not for users' security, but rather for company data on the app, so it is not a user's choice. I could not find any way to quit other than forcing an exit, which Apple discourages.
推荐答案
如果你不希望你的应用程序在后台保留在后台退出后,您可以通过将UIApplicationExitsOnSuspend键添加到应用程序的Info.plist文件并将其值设置为YES来明确选择退出后台执行模型。
"If you do not want your application to remain in the background when it is quit, you can explicitly opt out of the background execution model by adding the UIApplicationExitsOnSuspend key to your application’s Info.plist file and setting its value to YES.
当应用程序时选择退出,它在非运行状态,非活动状态和活动状态之间循环,并且永远不会进入后台状态或暂停状态。
When an application opts out, it cycles between the not running, inactive, and active states and never enters the background or suspended states.
当用户点击主页按钮退出应用程序时,applicationWillTermi nate:调用应用程序委托的方法,应用程序有大约五秒的时间来清理并退出,然后终止并返回到未运行状态。
When the user taps the Home button to quit the application, the applicationWillTerminate: method of the application delegate is called and the application has approximately five seconds to clean up and exit before it is terminated and moved back to the not running state."
这篇关于如何防止我的应用程序在iPhone上的后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!