当应用程序从后台终止时调用哪种方法。 [英] Which method called when app killed from background.

查看:56
本文介绍了当应用程序从后台终止时调用哪种方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个应用程序,因为我在应用程序启动时将一些变量保存在 NSUserdefaults 中。但是我想做的事情是,当应用程序从后台关闭时,它必须删除所有 NSUserdefaults 值。我怎样才能做到这一点。

I made an application in that i save some variables in NSUserdefaults when app launches. But i want to do the thing that when app close from background then it must remove all the NSUserdefaults value. how can i do this. please help me.

推荐答案

在iOS上,当您的应用在后台被杀死时,不会调用任何内容。

On iOS, nothing gets called when your app gets killed while in the background.

在您从前台移到后台时,应该存储所有必要的信息,以使应用恢复正常,如果它们被杀死并且再次发射。这样,iOS可以随时在后台随时取消您的应用程序。这是必要的,因为iOS会杀死您,例如,如果其他应用需要更多的内存;那时必须再次启动您的应用程序会适得其反。

At the point where you move from foreground to background, you are supposed to store all the information that is needed for your app to come back looking unchanged if it gets killed and launched again. By doing that, iOS has the freedom to kill your app at any time when in the background. This is necessary because iOS will kill you for example if it needs more memory for other apps; having to start your app again at that point would be totally counterproductive.

但是您所说的似乎表明您希望应用在后台被杀死时表现不同。那是错误的事情。用户永远不要注意到您的应用已被杀死。

But what you are saying seems to indicate that you want the app to behave differently if killed in the background. That's the wrong thing to do. The user never should notice that your app was killed.

这篇关于当应用程序从后台终止时调用哪种方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆