通讯录
系统通讯录
- AddressBook(iOS9之前)
#import
#import
遵循代理
实现代理方法
#pragma mark 选择联系人
- (void)handleAddContact:(UIButton *)sender
{
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc]init];
peoplePicker.peoplePickerDelegate = self;
peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false];
[self presentViewController:peoplePicker animated:YES completion:nil];
}#pragma mark 跳转联系人详情
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person{
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.displayedPerson = person;
personViewController.personViewDelegate = self;
[peoplePicker pushViewController:personViewController animated:YES];
}- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
// 如果点击的是电话选项,不进行响应,就是在真机中,点击电话cell,不会相应拨打电话
return (property == kABPersonPhoneProperty)?false:true;
}- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {if (property == kABPersonPhoneProperty)
{
//获取联系人的姓名
CFStringRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *firstNameStr = (__bridge_transfer NSString *)(firstName);
NSString *lastNameStr = (__bridge_transfer NSString *)(lastName);
NSString *name = @"";
// 小坑,10.0后如果用UIAddressBook,firstName和lastName居然反着
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0)
{
name = [NSString stringWithFormat:@"%@%@",lastNameStr?lastNameStr:@"",firstNameStr?firstNameStr:@""];
}
else
{
name = [NSString stringWithFormat:@"%@%@",firstNameStr?firstNameStr:@"",lastNameStr?lastNameStr:@""];
}// 获取手机号
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *phoneValue = https://www.it610.com/article/(__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(phones, identifier);
NSString *phoneNum1 = [phoneValue stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSString *phoneNum2 = [phoneNum1 stringByReplacingOccurrencesOfString:@"(" withString:@""];
NSString *phoneNum3 = [phoneNum2 stringByReplacingOccurrencesOfString:@")" withString:@""];
NSString *phoneNum4 = [phoneNum3 stringByReplacingOccurrencesOfString:@"(" withString:@""];
NSString *phoneNum5 = [phoneNum4 stringByReplacingOccurrencesOfString:@")" withString:@""];
_nameTextField.text = name;
_phoneTextField.text = phoneNum5;
CFRelease(phones);
}
NSLog(@"选择了某个属性");
}
- ContactsUI(iOS9之后)
#import
// 遵循代理
推荐 系统权限
通讯录 【通讯录】iOS开发进阶-Contacts/ContactUI学习和使用
推荐阅读
- 如何在Mac中的文件选择框中打开系统隐藏文件夹
- 单点登陆
- 操作系统|[译]从内部了解现代浏览器(1)
- 游乐园系统,助力游乐园管理
- 中国MES系统软件随工业化成长
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- Cesium|Cesium 粒子系统学习
- Android系统启动之init.rc文件解析过程
- 程序员|【高级Java架构师系统学习】毕业一年萌新的Java大厂面经,最新整理
- 算法回顾(SVD在协同过滤推荐系统中的应用)