iOS如何检测应用程序何时从进程中删除 [英] iOS how to detect when app was removed from process

查看:122
本文介绍了iOS如何检测应用程序何时从进程中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检测应用程序何时关闭的委托方法是什么。

What is the delegate method for detecting when application was closed.

我的意思是当用户点击此按钮时:

I mean when user tap this button:

我知道关于以下方法:

- (void)applicationDidEnterBackground:(UIApplication *)application;

- (void)applicationWillEnterForeground:(UIApplication *)application;

但是他们的工作并不像我预期的那样。例如,我使用了我的应用程序,并导航到某个屏幕。如果我锁定屏幕并返回应用程序,应用程序调用applicationWillEnterForeground但我不需要这个,因为我仍然在这个视图(例如测试屏幕视图),我不需要检查任何更改。但是,如果我的应用程序关闭,我开始从启动应用程序导航,例如主屏幕。因此,如果我的应用程序已关闭且我在主屏幕上,我需要检查以前是否有一些操作(例如,如果我在测试屏幕视图上通过测试)并提供此视图控制器(仅在我关闭应用程序的情况下)只是锁定它或输入背景)。

But they work not as I expected in my case. For example I have used my app and I have navigated to some screen. In case when I lock screen and go back to app the app calls applicationWillEnterForeground but I don't need this, because I am still on this view (for example Test Screen View)and I don't need to check any changes. But in case if my app closed I begin to navigate from start app for example Home Screen. So if my app was closed and I am on Home Screen I need to check if in previous time I had some actions (for example if I passed test on Test Screen View) and present this view controller (ONLY IN CASE IF I CLOSED APP NOT JUST LOCKED IT OR ENTER BACKGROUND).

感谢您的帮助。

推荐答案

你无法检测到这一点。来自 iOS应用程序编程指南(应用程序终止标题):

You can't detect this. From the iOS App Programming Guide ("App Termination" heading):


重要:如果您的应用目前暂停,则不会调用 applicationWillTerminate:方法。

Important: The applicationWillTerminate: method is not called if your app is currently suspended.

即使您开发了使用iOS SDK 4及更高版本的应用程序,您还必须准备
,以便在没有任何通知的情况下杀死您的应用程序。
用户可以使用多任务UI显式杀死应用程序。此外,如果内存受限制,
,系统可能会从
内存中删除应用程序以腾出更多空间。暂停的应用程序不会收到
终止的通知,但如果您的应用程序当前正在后台运行
状态(并且未暂停),系统将调用您的应用程序委托的
applicationWillTerminate:方法。您的应用无法通过此方法请求
请求额外的后台执行时间。

Even if you develop your app using iOS SDK 4 and later, you must still be prepared for your app to be killed without any notification. The user can kill apps explicitly using the multitasking UI. In addition, if memory becomes constrained, the system might remove apps from memory to make more room. Suspended apps are not notified of termination but if your app is currently running in the background state (and not suspended), the system calls the applicationWillTerminate: method of your app delegate. Your app cannot request additional background execution time from this method.

这篇关于iOS如何检测应用程序何时从进程中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆