跳转到通讯录

感谢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];

  }];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容