Question

I registered my main view controller for listening to UIApplicationDidBecomeActiveNotification because I want to display a UIAlertView each time the user enters my app :

        [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(someMethod:)
                                                 name:UIApplicationDidBecomeActiveNotification
                                               object:nil];

It's working like a charm, my only problem is if my app gets interrupted (by an UIAletView, such as a calendar event, or a popup asking for picture access confirmation), the notification gets called once the alert view's dismissed.

Any idea on how to detect ONLY when my app comes back from background mode ?

Was it helpful?

Solution

why don't you use AppDelegate method,

- (void)applicationWillEnterForeground:(UIApplication *)application
{
 //do whatever you want when app comes from background to foreground
}

OTHER TIPS

I know this is an old thread, but there is a UIApplicationWillEnterForegroundNotification. Works like this:

  [[NSNotificationCenter defaultCenter]addObserver:self
                                selector:@selector(myMethod)
                                    name:UIApplicationWillEnterForegroundNotification
                                        object:nil];

Best regards,

Gabriel Tomitsuka

Check state (active/background) of your application by following code:

UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateActive)
{

        /// your stuff of code:
}

Above code might be useful in your case:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top