iPhone 应用程序应进入后台,然后在几分钟不活动后关闭
我有一个应用程序,当用户单击 iPhone 的主页按钮时,该应用程序将发送到后台。但我希望它在几分钟不活动后关闭。这可能吗?
我在应用程序的 Info.plist 文件中看到 UIApplicationExitsOnSuspend 为 YES,但这会立即关闭应用程序。
I have an app which when the user clicks the iphone's home button, the application is sent to background. But I want it to be closed after a few minutes of inactivity. Is this possible?
I have seen UIApplicationExitsOnSuspend to YES in my app's Info.plist file, but this closes the app straight away.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的应用委托中,您必须实现
- (void)applicationDidEnterBackground:(UIApplication *)application
,在[UIApplication sharedApplication]< 上调用
beginBackgroundTaskWithExpirationHandler: ^()]
/code> 并存储结果。该应用程序的代码将继续在后台运行。然后,当您想要关闭应用程序时,请使用从上面代码中获取的任务标识符调用
endBackgroundTask:
。如果将此与 UIApplicationExitsOnSuspend 结合起来,您可能会得到您想要的行为......
In your app delegate, you must implement
- (void)applicationDidEnterBackground:(UIApplication *)application
, callingbeginBackgroundTaskWithExpirationHandler: ^()]
on[UIApplication sharedApplication]
and storing the result. The app's code will continue to run in a background.Then, when you want to close the app, call
endBackgroundTask:
with the task identifier you got from the code above.If you combine this with UIApplicationExitsOnSuspend, you might get the behaviour you want...