iOS调用系统通讯录获取姓名电话号码
2015-05-26 14:02
239 查看
iOS调用系统通讯录获取姓名电话号码
(iOS 8.0 Xcode6.3可以使用)
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];
}];
}
(iOS 8.0 Xcode6.3可以使用)
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];
}];
}
相关文章推荐
- iOS调用系统通讯录获取姓名电话号码(转)
- iOS 调用系统通讯录获取姓名电话号码
- iOS开发调用系统通讯录获取电话号码
- iOS 调用系统通讯录 获取联系人信息
- iOS调用系统的通讯录界面获取用户信息
- iOS 获取通讯录以及调用系统通讯录UI
- iOS --调用系统通讯录
- iOS开发--调用系统通讯录界面
- iPhone程序调用系统通讯录选择单个电话号码
- iOS 获取系统通讯录联系人信息
- iOS调用系统通讯录(适配iOS9、iOS10)
- ContentProvider获取系统的电话号码绑定到ListView以及跳转通讯录获区联系人信息绑定到前台。
- IOS调用系统联系人界面获取联系人信息
- IOS获取系统通讯录联系人信息
- iOS 获取通讯录里边的电话号码AddressBook
- IOS 获取系统通讯录
- iOS 调用系统相关功能(本机信息,手电筒,电话,短信,通讯录,内存,电池,亮度)
- IOS获取系统通讯录使用权限的优雅方式
- iOS开发-调用系统相机和相册获取照片示例
- ios开发之 -- 调用系统定位获取当前经纬度与地理信息