iOS 10测试版联系人通讯簿崩溃

iOS 10测试版联系人通讯簿崩溃,ios,contacts,addressbook,ios10,Ios,Contacts,Addressbook,Ios10,当点击通讯录中的任何联系人(在我的应用程序中)时,它在iOS 10测试版上崩溃,在iOS 9版本上工作正常 这是坠机日志 *** Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.' *** First throw call stack: (0x1cf11a07 0x1c6

当点击通讯录中的任何联系人(在我的应用程序中)时,它在iOS 10测试版上崩溃,在iOS 9版本上工作正常

这是坠机日志

*** Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'
*** First throw call stack:
(0x1cf11a07 0x1c62af63 0x1cf1194d 0x246f0f4f 0x246c6a71 0x1ce355eb 0x1ce2e19b 0x246c69cf 0x246c6883 0x25e4a375 0x2538f283 0x254204ef 0x25420bb1 0xe9da97 0xe9da83 0xea2321 0x1cecf18f 0x1cecd477 0x1ce1e6bd 0x1ce1e549 0x1e54ebfd 0x21f961e3 0x21f90947 0x966c9 0x1ca9e507)
libc++abi.dylib: terminating with uncaught exception of type NSException
下面是在我的应用程序中打开通讯簿的代码:

-(void)showContactPicker {
__weak RecieverSelectorViewController *weakSelf = self;
    ABPeoplePickerNavigationController* picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    picker.modalPresentationStyle = UIModalPresentationFullScreen;
    picker.modalTransitionStyle = UIModalPresentationPopover;
    [self presentViewController:picker
                       animated:YES
                     completion:^{
                         [weakSelf hideLoadingAnimation];

                         // animation to show view controller has completed.
                     }];
}



- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
    [self setSelectedPerson:person];
}

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person {
    [self setSelectedPerson:person];
}

-(void)setSelectedPerson:(ABRecordRef)person {


    NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person));

    ABMultiValueRef phoneRecord = ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phoneRecord, 0);

    self.isSenderReciever = NO;

    NSString *phone = [PorterUtils
                       extraLast10DigitsFromDigitString:[PorterUtils
                                                         extractNumberFromText:(__bridge_transfer NSString *)phoneNumber]];




    //Handling Social Media Contacts - Crash

    if(contactName.length>0 && phone.length>0){

      [self setRecieverName:contactName
                   number:phone];
       CFRelease(phoneRecord);
    }

}

它只在iOS 10公测版上崩溃。

在iOS 9中,通讯录API被弃用,取而代之的是更面向对象的

不要使用ABPeoplePickerViewController,请转到。

在您的info.plist中添加“隐私-联系人使用说明”

苹果论坛也提出了同样的问题。格斯利的原始答案如下


尝试使用CNContactPickerViewController(iOS9及以上版本):

添加ContactsUI.framework,导入框架,声明委托CNContactPickerDelegate

实施(在目标C中): 代表示例:
iOS 10不允许访问该联系人,直到我们提到使用它的原因。打开plist作为源代码在dict下添加以下代码,然后再次运行它

<key>NSContactsUsageDescription</key>
<string>$(PRODUCT_NAME) uses Contact</string>
NSContactsUsageDescription
$(产品名称)使用联系人

首先在
info.plist
中添加
NSContactsUsageDescription
,然后在AB请求访问块中显示控制器,如

ABAddressBookRequestAccessWithCompletion(contactPicker, { success, error in
  if success {
    self.presentViewController(self.contactPicker, animated: true, completion: nil)
  }
})
IOS 10现在需要用户权限才能访问媒体库、照片、, 照相机和其他类似的硬件。解决方法是添加 他们的密钥进入info.plist,并为用户描述我们的情况 使用他们的数据,iOS已经需要访问权限 麦克风、摄像头和媒体库(iOS6、iOS7),但从 iOS10如果你不提供你为什么这么做的说明,应用程序将崩溃 我们正在请求许可

您可以在Info.plist文件中指定所有Cocoa密钥的列表

照片:

Key       :  Privacy - Photo Library Usage Description    
Value   :  $(PRODUCT_NAME) photo use
Key        :  Privacy - Microphone Usage Description    
Value    :  $(PRODUCT_NAME) microphone use
Key       :  Privacy - Camera Usage Description   
Value   :  $(PRODUCT_NAME) camera use
麦克风:

Key       :  Privacy - Photo Library Usage Description    
Value   :  $(PRODUCT_NAME) photo use
Key        :  Privacy - Microphone Usage Description    
Value    :  $(PRODUCT_NAME) microphone use
Key       :  Privacy - Camera Usage Description   
Value   :  $(PRODUCT_NAME) camera use
摄像机:

Key       :  Privacy - Photo Library Usage Description    
Value   :  $(PRODUCT_NAME) photo use
Key        :  Privacy - Microphone Usage Description    
Value    :  $(PRODUCT_NAME) microphone use
Key       :  Privacy - Camera Usage Description   
Value   :  $(PRODUCT_NAME) camera use

Swift 3

// This example allows the display and selection of email addresses only.
if #available(iOS 9.0, *) {
    let picker = CNContactPickerViewController()
    let arrKeys = [CNContactEmailAddressesKey] // array of properties to display
    picker.displayedPropertyKeys = arrKeys
    picker.delegate = self
    present(picker, animated: true, completion: nil)
}
代表示例

    @available(iOS 9.0, *)
    func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) {
        let emailAddress = contactProperty.value as? String     
    }

检查您是否提供了有效的密钥,如

@[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactEmailAddressesKey]
当他们从CNContact对象请求时


例如:如果您需要呼叫contact.emailAddresses,则必须从(CNContactEmailAddressesKey)数组中提供它。

我们需要查看stacktrace。我如何获得它?您是否有目标c代码?没有,但转换目标碎屑帮助很简单,如何从CNContacts对象中获取名称和号码?当我使用“givenname”或“nameprefix”或NameSuffix时,我只得到部分名称。您描述的问题与OP得到的错误不同(CNPropertyNotFetchedException)。虽然您的解决方案适合您的问题,但在这种情况下并不正确:)既然CNContactPickerViewController可从iOS 9获得,我应该如何同时支持iOS 8和iOS 10?@Kenpachi您必须检查系统版本。如果是iOS 9或10,则需要使用Contacts框架。如果是iOS 8,则需要使用通讯簿。次要修复:
peoplePicker.displayedPropertyKeys=arrkeys应为
peoplePicker.displayedPropertyKeys=arrKeys修复了它。谢谢@Billy(: