I'm sure this is something very straight forward but I can't find the information anywhere. I need my app to reload some information when it is opened from the background (not a fresh open). Any ideas how to do that?
Your app can override - (void)applicationWillEnterForeground:(UIApplication *)application in your UIApplicationDelegate.
You also have your controller become an observer for UIApplicationWillEnterForegroundNotification. According to Apple Docs: Posted shortly before an application leaves the background state on its way to becoming the active application.
Sample code with controller in NIB file, otherwise override - (id)init:
- (void)awakeFromNib {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wakeUp:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
- (void)wakeUp:(NSNotification *)pNotification {
NSLog(@"Name: %@", [pNotification name]);
NSLog(@"Object: %@", [pNotification object]);
NSLog(@"I am waking up");
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Take a look at the documentation for applicationDidBecomeActive and applicationWillEnterForeground in the UIApplicationDelegate protocol:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With