iPhone - Send event to objects to tell them that the app is 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];
精彩评论