开发者

iPhone - Send event to objects to tell them that the app is in background

开发者 https://www.devze.com 2023-03-22 03:46 出处:网络
I have some tasks that does some jobs, and I\'d like to route them an event when the app goes in background.

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, wit开发者_如何转开发hout 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 ?


When the application enters the background, the UIApplicationDidEnterBackgroundNotification is sent (iOS 4.0 and later). Make your objects observe this notification:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(doWhatNeededBecauseAppHasGoneInBackground)
                                             name:UIApplicationDidEnterBackgroundNotification
                                           object:nil];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号