Husein Behboodi Rad Husein Behboodi Rad - 4 months ago 83
Objective-C Question

ABAddressBookRequestAccessWithCompletion crashes on iOS 10

I use below code to access contacts in my iOS application. It was working fine in iOS<10 but with Xcode 8 and iOS 10 it crashes:

- (void)btcContacts_tap {
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted) {
_addressBookController = [[ABPeoplePickerNavigationController alloc] init];

[[_addressBookController navigationBar] setBarStyle:UIBarStyleBlack];

_addressBookController.delegate = self;
[_addressBookController setPredicateForEnablingPerson:[NSPredicate predicateWithFormat:@"%K.@count > 0", ABPersonPhoneNumbersProperty]];
[_addressBookController setPeoplePickerDelegate:self];
[self presentViewController:_addressBookController animated:YES completion:nil];
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
[self showMessage:NSLocalizedStringFromTable(@"PLEASE_GRANT_CONTACTS", LIApplicationLanguage(), nil) andAdvertise:@"" andService:nil andTransactionState:kTTTransactionStateInfo];
});
}
});
}


I have set
NSSetUncaughtExceptionHandler
to a method for logging the crash report but even the exception handler is not calling...

Does someone else faced this problem too?

Answer

ABAddressBookRef and ABAddressBookRequestAccessWithCompletion are deprecated from iOS 9 so you can not use them in iOS 10.

For more information see below link: https://developer.apple.com/library/ios/documentation/AddressBook/Reference/ABAddressBookRef_iPhoneOS/index.html