【发布时间】:2016-11-03 14:50:03
【问题描述】:
我这样调用联系人选择器视图:
- (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];
}
}
}
}
NSLog 为联系人输出以下内容:<CNContact: 0x78e56e50: identifier=1861C9BD-143B-4E93-8475-F9079F5D6192, givenName=Kate, familyName=Bell, organizationName=Creative Consulting, phoneNumbers=(not fetched), emailAddresses=(not fetched), postalAddresses=(not fetched)>
这只发生在模拟器和 iOS9 iPad 上。我的 iOS10 iPhone 没有出现错误。
【问题讨论】:
标签: objective-c ios9 cncontact