如何知道应用程序是否被用户或 iOS 终止(后台 10 分钟后)
重新启动应用程序时如何知道应用程序是被用户终止还是被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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的应用程序处于挂起状态,则无论谁杀死了应用程序 iOS 或用户,
applicationWillTerminate
都永远不会被调用。您的
applicationWillTerminate
仅当您的应用程序处于后台并且被终止(由 iOS 或用户)时才会调用,术语“后台”意味着它在后台运行而不是处于挂起状态。只需阅读 此参考
这是各种状态的表
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
Here is the table of various states
如果系统资源不足,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.