iPhone - 向对象发送事件以告诉它们应用程序处于后台
我有一些任务可以完成一些工作,并且我想在应用程序进入后台时为它们路由一个事件。
为此,我计划在编译时强制它们实现类似 - (void) doWhatNeededBecauseAppHasGoneInBackground; 的方法;
我该怎么做呢?
是否有一种常见的方法可以将应用程序进入或将进入后台的事实路由到内存中的现有对象?我的意思是,不冒错过一些已实施方法的风险吗?我看到使用 [MyClass copy] 调用的每个类都需要实现 NSCoding 协议,为此,它必须实现一些方法。这可能是一个想法吗?
I have some tasks that does some jobs, and I'd like to route them an event when the app goes in background.
To do so, I plan to force them at compile time to implement a method like - (void) doWhatNeededBecauseAppHasGoneInBackground;
How should I do that ?
Is there a common way to route to existing objects in memory the fact that the app went, or is going to go in background ? I mean, without risking to miss some implemented methods ? I see that each class that is called with [MyClass copy] needs to implement the NSCoding protocol, and doing that, it has to implement some methods. Could this be an idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当应用程序进入后台时, UIApplicationDidEnterBackgroundNotification 已发送(iOS 4.0 及更高版本)。让你的对象观察这个通知:
When the application enters the background, the UIApplicationDidEnterBackgroundNotification is sent (iOS 4.0 and later). Make your objects observe this notification: