For some reason, my app seems to take forever when I try to perform a segue. The mysterious loading time only appears, after I request permission for the AddressBook - if the Permission is already granted, there is no issue at all.
So, before actually using the Segue, i'm doing something like this:
Requesting Permission for Address Book
-(void)requestPermissionForContacts
{
ABAddressBookRef addressbook = ABAddressBookCreateWithOptions(nil, nil);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined)
{
ABAddressBookRequestAccessWithCompletion(addressbook, ^(bool granted, CFErrorRef error) {
if (granted)
{
NSLog(@"granted");
[self didGrantPermissions];
} else{
NSLog(@"denied");
[self didNotGrantPermission];
}
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
{
[self didGrantPermissions];
} else {
[self didNotGrantPermission];
}
CFRelease(addressbook);
}
Whatever they user clicks:
-(void)didGrantPermissions
{
[self performSegueWithIdentifier:@"addressBook" sender:nil];
}
-(void)didNotGrantPermission
{
[[[UIAlertView alloc] initWithTitle:@"Address Book" message:@"To access this feature, please allow us to access your Address Book" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] show];
}
And after that,
prepareForSegue
if ([segue.identifier isEqualToString:@"addressBook"])
{
CWAddressBookViewController *abvc = segue.destinationViewController;
abvc.delegate = self;
abvc.addressType = self.addressType;
}
If it is the first time, the App is accessing this view (so, if its still asking for permission) it takes quite a while (20sec!) until -(void)viewDidLoad is being called on CWAddressBookViewControlller
If the permission is already granted, it is performing the segue as expected in the blink of an eye.
Any idea what im doing wrong here?