Ranjit
Ranjit

Reputation: 4636

When notification is dragged and released, ApplicationBecomeActive gets called in iOS

I have password option in my app, so if user sets a password, then I show a password page first when app becomes active and user should enter the password to use the app

I have written the code this way

- (void)applicationDidBecomeActive:(UIApplication *)application
{
     if([password length])
     {

                    EnterPasswordViewController *passwordView = [[EnterPasswordViewController alloc] initWithNibName:@"EnterPasswordViewController" bundle:nil];
                    [self presentViewController:passwordView animated:YES completion:NULL];

     }
}

This works but the problem is that whenever I am inside the app and when I just drag the notifications from the top and leave it, what I have seen is the applicationDidBecomeActive gets called and because of this, password page is shown again, So I am not understanding how to solve this

Regards Ranjit.

Upvotes: 0

Views: 52

Answers (1)

SomeGuy
SomeGuy

Reputation: 9690

Consider presenting your password controller inside the -applicationWillEnterForeground: method instead.

willEnterForeground is called only when your app is closed completely (into the background or the device is locked) and then comes back to the foreground

The one you're currently using will also get called when the system presents an alert for you, such as asking the user to allow push notifications even for your app.

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Present password controller
}

Alternatively you could reverse the logic and present it when your app enters the background, as opposed to entering the foreground.

Upvotes: 2

Related Questions