如何知道应用程序是否被用户或 iOS 终止(后台 10 分钟后)

发布于 2024-12-03 09:33:55 字数 135 浏览 0 评论 0原文

重新启动应用程序时如何知道应用程序是被用户终止还是被iOS终止>

“按用户”是指“通过双击主页按钮并按 - 按钮”。被用户“通过 iOS”杀死

意味着“应用程序进入后台运行状态,iOS 在 10 分钟后终止应用程序”

How to know whether app is terminated by user or by iOS when restart app>

'By user' means "by Double-clicking Home Button and pressing - button". killed by user

'By iOS' means "app become background running state, and iOS terminate app after 10 mins"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸印温柔 2024-12-10 09:33:55

如果您的应用程序处于挂起状态,则无论谁杀死了应用程序 iOS 或用户,applicationWillTerminate 都永远不会被调用。

您的 applicationWillTerminate 仅当您的应用程序处于后台并且被终止(由 iOS 或用户)时才会调用,术语“后台”意味着它在后台运行而不是处于挂起状态。

只需阅读 此参考

applicationWillTerminate:—让您知道您的应用程序正在被终止。如果您的应用程序被挂起,则不会调用此方法。

这是各种状态的表
在此处输入图像描述

后台 - 应用程序位于后台并执行代码。大多数应用程序在暂停之前会短暂进入此状态。但是,请求额外执行时间的应用程序可能会保持此状态一段时间。此外,直接启动到后台的应用程序会进入此状态,而不是非活动状态。有关如何在后台执行代码的信息,请参阅后台执行。

If your app is in suspended state the applicationWillTerminate will never get called regardless who killed the app iOS or user.

Your applicationWillTerminate will only call when your app is in background and it gets killed (either by iOS or user) the term background means that it is running in background not in suspended state.

Just read this reference

applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.

Here is the table of various states
enter image description here

Background - The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see Background Execution.

数理化全能战士 2024-12-10 09:33:55

如果系统资源不足,iOS 可能会终止您的应用 - 如果发生这种情况,您将看到 applicationWillTerminate

过去,如果用户杀死了应用程序(任务管理器,通过双击按钮,然后点击红色“-”),则会发出 SIGKILL 并且不会调用 applicationWillTerminate。 2013 年中的一份报告表明这种情况已发生变化,现在调用了 applicationWillTerminate

您可以使用 NSUserDefaults 在 applicationWillTerminate 中写入一些状态位,以注意此函数已被调用,并且可能是系统终止而不是用户终止。

iOS might terminate your app if system resources are low - if this happens, you will see applicationWillTerminate.

It used to be that if a user killed the app (task manager, via the button double-click and then hits the red '-') it's a SIGKILL and applicationWillTerminate is not called. A report mid-2013 suggests this has changed and applicationWillTerminate now is called.

You could use NSUserDefaults to write some state bit in applicationWillTerminate to note that this function was called and presumably that's a system kill rather than a user kill.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文