gpt4 book ai didi

iOS 如何检测应用程序何时从进程中删除

转载 作者:IT王子 更新时间:2023-10-29 08:18:18 26 4
gpt4 key购买 nike

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

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

enter image description here

我知道下面的方法:

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

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

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

感谢您的帮助。

最佳答案

你无法检测到这一点。来自iOS App Programming Guide (“应用程序终止”标题):

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

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 如何检测应用程序何时从进程中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17840893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com