這將允許您打開人員選擇器並從聯繫人中選擇信息。我不知道你需要什麼信息,但你明白了。
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
[self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier];
NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person));
self.nameField.text = [NSString stringWithFormat:@"%@", contactName ? contactName : @"No Name"];
ABMultiValueRef phoneRecord = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phoneRecord, 0);
self.phoneField.text = (__bridge_transfer NSString *)phoneNumber;
CFRelease(phoneRecord);
ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
CFStringRef emailField = ABMultiValueCopyValueAtIndex(email, 0);
self.emailField.text = (__bridge_transfer NSString *)emailField;
CFRelease(email);
CFDataRef photo = ABPersonCopyImageData(person);
UIImage* image = [UIImage imageWithData:(__bridge NSData*)photo];
if(photo)
CFRelease(photo);
if(image)
self.myImageView.image = image;
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
[self dismissViewControllerAnimated:YES completion:nil];
return NO; }
我也看到這個問題 - 只在iOS 8設備上,而不在模擬器中。控制器僅顯示名稱,而不顯示其他屬性。任何人都知道解決方法? – montuno 2014-11-11 00:34:10