ABAddressBookRequestAccessWithCompletion 在 iOS 10 时崩溃
ABAddressBookRequestAccessWithCompletion crashes on iOS 10
我使用以下代码访问我的 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
设置为记录崩溃报告的方法,但即使是异常处理程序也没有调用...
其他人也遇到过这个问题吗?
iOS 10:
您需要将 NSContactsUsageDescription
放入您的 plist 中。喜欢:
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) uses photos</string>
查看所有使用说明here。
使用CNContactStore
,ABAddressBookRequestAccessWithCompletion
折旧。
enter link description here
我使用以下代码访问我的 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
设置为记录崩溃报告的方法,但即使是异常处理程序也没有调用...
其他人也遇到过这个问题吗?
iOS 10:
您需要将 NSContactsUsageDescription
放入您的 plist 中。喜欢:
<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) uses photos</string>
查看所有使用说明here。
使用CNContactStore
,ABAddressBookRequestAccessWithCompletion
折旧。
enter link description here