iOS10上的通讯录崩溃 [英] Address Book crash on iOS10
问题描述
从联系人选择器中选择联系人会使iOS10.0中的应用程序崩溃。使用 ABPeoplePickerNavigationController
显示联系人选择器,如下所示:
Selecting a contact from contact picker crashes the app in iOS10.0. Contacts picker is shown using ABPeoplePickerNavigationController
like this:
let contactsPicker = ABPeoplePickerNavigationController()
contactsPicker.peoplePickerDelegate = self
self.presentViewController(contactsPicker, animated: true, completion: nil)
这是崩溃日志中的堆栈跟踪:
Here is the stack trace from crash log:
*** Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105a1c34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001052cd21e objc_exception_throw + 48
2 CoreFoundation 0x0000000105a85265 +[NSException raise:format:] + 197
3 Contacts 0x000000010dc6d96f -[CNContact sectionForSortingByFamilyName] + 160
4 Contacts 0x000000010dc3e18e __55-[CNContact(iOSABCompatibility) overwritePerson:error:]_block_invoke + 44
5 CoreFoundation 0x00000001059ad2fd __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 77
6 CoreFoundation 0x00000001059ad1df -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 207
7 Contacts 0x000000010dc3e0f4 -[CNContact(iOSABCompatibility) overwritePerson:error:] + 240
8 Contacts 0x000000010dc3dfc0 -[CNContact(iOSABCompatibility) detachedPersonWithError:] + 46
9 AddressBookUI 0x00000001057bdd77 -[ABPeoplePickerNavigationController contactPicker:didSelectContact:] + 145
10 ContactsUI 0x0000000112396eb2 -[CNContactPickerViewController pickerDidSelectContact:property:] + 306
11 ContactsUI 0x000000011243ee6f -[CNContactPickerHostViewController pickerDidSelectContact:property:] + 95
12 ContactsUI 0x000000011243f5ec __71-[CNContactPickerExtensionHostContext pickerDidSelectContact:property:]_block_invoke + 66
$ b
我已经在info.plist中添加了 NSContactsUsageDescription
,如 iOS 10 Beta上的通讯录崩溃,但这没有帮助,我不能使用 CNContactPickerViewController
,因为我需要支持iOS8设备。
I have already added NSContactsUsageDescription
in the info.plist as discussed on Contact Address book crash on iOS 10 beta but that didn't help and I can't use CNContactPickerViewController
as I need to support iOS8 devices.
推荐答案
Imran Raheem
Imran Raheem
来自Erdekhayser的解决方案( iOS 10 beta )
From Erdekhayser's solution (Contact Address book crash on iOS 10 beta)
您可以使用此方法检查CNContactPickerViewController是否可用?
you can use this method to check CNContactPickerViewController is available?
if (NSClassFromString(@"CNContactPickerViewController")) {
// iOS 9, 10, use CNContactPickerViewController
CNContactPickerViewController *picker = [[CNContactPickerViewController alloc] init];
picker.delegate = self;
picker.displayedPropertyKeys = @[CNContactPhoneNumbersKey];
[pr presentViewController:picker animated:YES completion:nil];
}else{
// iOS 8 Below, use ABPeoplePickerNavigationController
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[pr presentViewController:picker animated:YES completion:nil];
}
这篇关于iOS10上的通讯录崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!