当我的应用程序在ios中的后台终止时如何执行代码

当我的应用程序在ios中的后台终止时如何执行代码,第1张

概述在iOS中,我们都知道有AppDelegate方法applicationWillTerminate,并且当我的应用程序在当前正在运行时关闭时(即不在后台),它会被调用.但是当我的应用程序在后台运行时终止(由用户关闭或被 *** 作系统杀死)时,我想做某事(例如保存数据). PS:我的应用可以在后台运行. 你有什么解决办法?谢谢. 抱歉,您应该使用applicationWillTerminate: This 在iOS中,我们都知道有AppDelegate方法applicationWillTerminate,并且当我的应用程序在当前正在运行时关闭时(即不在后台),它会被调用.但是当我的应用程序在后台运行时终止(由用户关闭或被 *** 作系统杀死)时,我想做某事(例如保存数据).

PS:我的应用可以在后台运行.

你有什么解决办法?谢谢.

解决方法 抱歉,您应该使用applicationWillTerminate:

This method lets your app kNow that it is about to be terminated and
purged from memory entirely. You should use this method to perform any
final clean-up tasks for your app,such as freeing shared resources,
saving user data,and invalIDating timers. Your implementation of this
method has approximately five seconds to perform any tasks and return.
If the method does not return before time expires,the system may kill
the process altogether.

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.

因此,如果您需要在用户手动终止应用程序时保存数据,请使用applicationDIDEnterBackground,如果您的应用程序支持后台模式,则调用它.

总结

以上是内存溢出为你收集整理的当我的应用程序在ios中的后台终止时如何执行代码全部内容,希望文章能够帮你解决当我的应用程序在ios中的后台终止时如何执行代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1058766.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存