我使用以下代码访问iOS应用程序中的联系人。它在iOS< 10中运行良好,但是Xcode 8和iOS 10崩溃了:
- (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];
});
}
});
}
我已将NSSetUncaughtExceptionHandler
设置为记录崩溃报告的方法,但即使异常处理程序也未调用...
其他人是否也遇到过这个问题?
答案 0 :(得分:22)
iOS 10:
您需要将NSContactsUsageDescription
放入plist中。像:
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) uses photos</string>
查看所有使用说明here。