应用程序最佳实践DidEnterBackground [英] Best practice for applicationDidEnterBackground

查看:125
本文介绍了应用程序最佳实践DidEnterBackground的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,该应用程序需要在应用程序调用applicationDidEnterBackground时将其状态的某些部分重置为默认状态.我想知道的一种更好的做法是,获取指向需要重置的视图的指针,然后在应用程序委托中立即重置需要重置的属性,还是应该发布NSNotification,应用正在进入后台,并让视图控制器在其内部对其进行清理.也许还有另一种我没想到的方法.

I am in the middle of writing an application that needs to reset certain parts of its state to a default state when the application calls applicationDidEnterBackground. What I would like to know is if it is a better practice to get a pointer to the view that needs to be reset and then reset the properties that need to be reset right there in the app delegate, or should I post an NSNotification that the app is entering the background and have the view controller do it's cleanup within itself. Or maybe there's another method I'm not thinking of.

我非常感谢您的投入.

推荐答案

这些通知已经发布.只需在您的控制器类中订阅该事件,然后在该类中做任何您需要的事情即可.

These notifications get posted already. Just subscribe to the event in your controller class(es) and do whatever you need to there.

从文档中

应用程序还会发布一个 UIApplicationDidEnterBackgroundNotification 通知大约在同一时间 调用此方法使感兴趣 反对回应的机会 过渡.

The application also posts a UIApplicationDidEnterBackgroundNotification notification around the same time it calls this method to give interested objects a chance to respond to the transition.

查看全文

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