I'm accessing ABAddressBook using the following code:
+ (void)connectToAddressBook {
if(!_addressBook)
{
CFErrorRef error;
_addressBook = ABAddressBookCreateWithOptions(NULL, &error);
NSLog(@"Address book %@", _addressBook);
if (error != nil) {
NSLog(@"ERROR WHILE ACCESSING ADDRESS BOOK: %@", CFBridgingRelease(error));
CFRelease(error);
}
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(_addressBook, ^(bool granted, CFErrorRef error) {
_isAccessToContactsAllowed = granted;
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
_isAccessToContactsAllowed = YES;
}
else {
_isAccessToContactsAllowed = NO;
}
}
}
Address book opens fine, but for some reason error is not nil and logs the name of the current class:
ERROR WHILE ACCESSING ADDRESS BOOK: MyContactManager
Why is error not nil? Is my code somehow wrong? How can I detect and stop trying to access the address book in the case of a real error?