Jens
Jens

Reputation: 6383

Asking for permission sets back navigation stack

I have 3 ViewControllers in the stack of a navigation controller. On the third ViewController there is a button that will add a contact to the address book.

If the app has not been used and this button is pressed the first time I am checking the authorization status and if it is not determined I am asking for permission with ABAddressBookRequestAccessWithCompletion.

When this was answered and the app is supposed to go back to the last VC on my navigation stack it sets back all VCs and goes alle the way back to the first VC in the navigation stack.

Is this intentional behavior?

Just in case it is useful here's the code to ask for permission:

else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {

    // ask for access to address book.
    ABAddressBookRequestAccessWithCompletion(ABAddressBookCreateWithOptions(NULL, nil), ^(bool granted, CFErrorRef error) {
        if (!granted){
            NSLog(@"Addressbook access was denied");
            return;
        }
        NSLog(@"Addressbook access was authorized");
        //[self addContactToAddressbook];
    });

} 

(I have temporarily commented the call addContactToAddressbook to make sure it does not interfere.)

Upvotes: 1

Views: 52

Answers (1)

Jens
Jens

Reputation: 6383

Just to complete this (in case others stumble upon this). The important insight on this is:

When you call ABAddressBookRequestAccessWithCompletion to ask for permission to the address book your app seems to be in status "inactive" (while the dialog is up).

Consecutively, when the user answers the question the method:

- (void)applicationDidBecomeActive:(UIApplication *)application

will be called.

(In my case this lead to resetting the navigation stack - which was the reason for my question.)

Upvotes: 0

Related Questions