gpt4 book ai didi

ios - 系统检测 iOS 应用程序后台终止

转载 作者:行者123 更新时间:2023-11-29 11:36:31 25 4
gpt4 key购买 nike

我想要实现的是检测系统何时在后台运行(未挂起)时终止应用程序。根据this article它可以通过消除过程来完成。其中一个步骤是确定用户没有强制退出应用程序。我假设这是通过检查是否调用了 applicationWillTerminate 来完成的。但是,根据 Apple 的文档,系统也可以调用此方法,因此我不确定它是如何消除该选项的。

For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.

是否可以检测后台系统终止,如果可以,我在这里缺少什么?

最佳答案

App Programming Guide for iOS: The App Life Cycle说:

Suspended apps receive no notification when they are terminated; the system kills the process and reclaims the corresponding memory. If an app is currently running in the background and not suspended, the system calls the applicationWillTerminate: of its app delegate prior to termination. The system does not call this method when the device reboots.

In addition to the system terminating your app, the user can terminate your app explicitly using the multitasking UI. User-initiated termination has the same effect as terminating a suspended app. The app’s process is killed and no notification is sent to the app.

以上与实证检验一致。

在那Reducing FOOMs in the Facebook iOS app文章中,他们提到应用程序确实“在应用程序上次打开时收到终止调用”的强制退出情况:这仅适用于应用程序正在积极运行并且用户强制退出它的情况。但是,如果用户首先返回到主屏幕(或以其他方式暂停应用程序),然后强制终止应用程序,您将不会收到终止通知。

最重要的是,如果应用程序在终止时被挂起,我认为您没有任何可靠的方法知道它是由于内存压力还是由于用户强制退出而被抛弃。 FOOM/BOOM 文章中考虑的强制退出场景显然仅适用于强制退出时应用正在运行的情况。

关于ios - 系统检测 iOS 应用程序后台终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48975158/

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