Error ABAddressBookRequestAccessWithCompletion on iOS 10

I use the code below to access contacts in an iOS app. It worked fine on 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 installed NSSetUncaughtExceptionHandlera crash report in the registration method, but even the exception handler does not raise ...

Has anyone else encountered this problem?

+4
source share
2 answers

iOS 10:

You need to put NSContactsUsageDescriptionin your plist. How:

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

See all usage descriptions here .

+22
source

Use CNContactStoreis ABAddressBookRequestAccessWithCompletiondepreciating. enter the link here

0

All Articles