Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c CNContactPickerViewController获取错误(CNPropertyNotFetchedException)-目标-C_Objective C_Ios9_Cncontact - Fatal编程技术网

Objective c CNContactPickerViewController获取错误(CNPropertyNotFetchedException)-目标-C

Objective c CNContactPickerViewController获取错误(CNPropertyNotFetchedException)-目标-C,objective-c,ios9,cncontact,Objective C,Ios9,Cncontact,我调用联系人选取器视图,如下所示: - (void)openContacts { CNContactPickerViewController *picker = [[CNContactPickerViewController alloc] init]; picker.delegate = self; picker.displayedPropertyKeys = @[CNContactGivenNameKey]; [self presentViewContro

我调用联系人选取器视图,如下所示:

- (void)openContacts {
    CNContactPickerViewController *picker = [[CNContactPickerViewController alloc] init];

    picker.delegate = self;

    picker.displayedPropertyKeys = @[CNContactGivenNameKey];

    [self presentViewController:picker animated:YES completion:nil];
}
我使用此委托方法处理选择:

- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContacts:(NSArray<CNContact *> *)contacts {
    for (CNContact *contact in contacts) {
        NSLog(@"%@",contact);
        NSString *phone;
        NSString *mobilePhone;

        for (CNLabeledValue *label in contact.phoneNumbers) {
            if ([label.label isEqualToString:CNLabelPhoneNumberMobile] || [label.label isEqualToString:CNLabelPhoneNumberiPhone]) {
                mobilePhone = [label.value stringValue];
            } else if ([label.label isEqualToString:CNLabelPhoneNumberMain]) {
                phone = [label.value stringValue];
            }
        }
    }
}
-(无效)联系人选取器:(CNContactPickerViewController*)选取器未选择联系人:(NSArray*)联系人{
用于(CNContact*联系人中的联系人){
NSLog(@“%@”,联系人);
NSString*电话;
NSString*移动电话;
用于(联系人电话号码中的CNLabeledValue*标签){
if([label.label IseQualtString:CNLabelPhoneNumberMobile]| |[label.label IseQualtString:CNLabelPhoneNumberPhone]){
手机=[label.value-stringValue];
}else if([label.label IsequalString:CNLabelPhoneNumberMain]){
phone=[label.value stringValue];
}
}
}
}
NSLog为联系人输出以下内容:


这只发生在模拟器和iOS9 iPad上。我的iOS10 iPhone没有出现任何错误。

您应该先获得许可。然后你可以给皮克看

CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error)
 {
         CNContactPickerViewController *picker = [[CNContactPickerViewController alloc] init];
         picker.delegate = self;
         picker.displayedPropertyKeys = @[CNContactGivenNameKey];
         [self presentViewController:picker animated:YES completion:nil];
 }];
在这种情况下,您将始终显示选择器,而不依赖于用户的选择。因此,您应该像这样检查物业可用性:

if ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusAuthorized)
    {

    }

你应该先申请许可。然后你可以给皮克看

CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error)
 {
         CNContactPickerViewController *picker = [[CNContactPickerViewController alloc] init];
         picker.delegate = self;
         picker.displayedPropertyKeys = @[CNContactGivenNameKey];
         [self presentViewController:picker animated:YES completion:nil];
 }];
在这种情况下,您将始终显示选择器,而不依赖于用户的选择。因此,您应该像这样检查物业可用性:

if ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusAuthorized)
    {

    }