Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 695
Husein Behboudi Rad Avatar asked Jul 09 '16 14:07

Husein Behboudi Rad


2 Answers

iOS 10:

You need to put the NSContactsUsageDescription in your plist. Like:

<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) uses photos</string>

See all usage descriptions here.

like image 89
Benny Davidovitz Avatar answered Oct 18 '22 09:10

Benny Davidovitz


Use CNContactStore , ABAddressBookRequestAccessWithCompletion is depreciated. enter link description here

like image 34
Raza.najam Avatar answered Oct 18 '22 11:10

Raza.najam