感谢http://blog.csdn.net/idoshi201109/article/details/46007125
1、导入头文件。
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
2、添加协议
@interface NewAddressViewController ()<ABPeoplePickerNavigationControllerDelegate>
3、实例化
ABPeoplePickerNavigationController * vc = [[ABPeoplePickerNavigationController alloc] init];
vc.peoplePickerDelegate = self;
[self presentViewController:vc animated:YES completion:nil];
4、实现协议方法
#pragma mark -- ABPeoplePickerNavigationControllerDelegate
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
ABMultiValueRef valuesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFIndex index = ABMultiValueGetIndexForIdentifier(valuesRef,identifier);
//电话号码
CFStringRef telValue = ABMultiValueCopyValueAtIndex(valuesRef,index);
//读取firstname
//获取个人名字(可以通过以下两个方法获取名字,第一种是姓、名;第二种是通过全名)。
//第一中方法
// CFTypeRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
// CFTypeRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
// //姓
// NSString * nameString = (__bridge NSString *)firstName;
// //名
// NSString * lastString = (__bridge NSString *)lastName;
//第二种方法:全名
CFStringRef anFullName = ABRecordCopyCompositeName(person);
[self dismissViewControllerAnimated:YES completion:^{
self.telLabel.text = (__bridge NSString *)telValue;
// self.nameLabel.text = [NSString stringWithFormat:@"%@%@",nameString,lastString];
self.nameLabel.text = [NSString stringWithFormat:@"%@",anFullName];
}];
}
网友评论