- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
ABPeoplePickerNavigationController *pickController = [[ABPeoplePickerNavigationController alloc]init];
pickController.peoplePickerDelegate = self;
[self presentViewController:pickController animated:YES completion:^{
}];
}
//選中一個聯(lián)系人的代理方法(實(shí)現(xiàn)這個方法后就不會進(jìn)入聯(lián)系人的詳細(xì)界面)
-
(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person{
NSLog(@"====%@",person);
CFStringRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);// 這樣的橋接方式將cf的轉(zhuǎn)為foundtion后就不用再管理內(nèi)存了。
NSString first = (__bridge_transfer NSString)(firstName);
NSLog(@"%@",first);
// 獲取聯(lián)系人的電話號碼(獲取到的是個數(shù)組,而且數(shù)組里面存放的好像是字典)
ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFIndex count = ABMultiValueGetCount(phone);
for (int i = 0 ; i<count; i++) {
// 獲取手機(jī)號碼的的名字
NSString phoneName= (__bridge_transfer NSString)(ABMultiValueCopyLabelAtIndex(phone, i));
// 獲取手機(jī)號碼
NSString phoneVaule = (__bridge_transfer NSString)(ABMultiValueCopyValueAtIndex(phone, i));
NSLog(@"==%@,%@",phoneName,phoneVaule);
}
CFRelease(phone);
}
//選中一個聯(lián)系人的一個屬性時的方法候調(diào)用的方法(如果實(shí)現(xiàn)了這個方法選擇聯(lián)系人的屬性就會跳出這個頁面项滑,自動退出當(dāng)前的控制器)遭居。
-
(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
// 在這里面也是對person 這個對像進(jìn)行操作和,上面的代理操作類似
}
// 點(diǎn)擊取消按鈕會執(zhí)行的方法
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
NSLog(@"你點(diǎn)擊了取消按鈕");
}