- (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:^{
}];
}
//選中一個聯系人的代理方法(實現這個方法后就不會進入聯系人的詳細界面)
-
(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person{
NSLog(@"====%@",person);
CFStringRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
CFStringRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);// 這樣的橋接方式將cf的轉為foundtion后就不用再管理內存了。
NSString first = (__bridge_transfer NSString)(firstName);
NSLog(@"%@",first);
// 獲取聯系人的電話號碼(獲取到的是個數組,而且數組里面存放的好像是字典)
ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFIndex count = ABMultiValueGetCount(phone);
for (int i = 0 ; i<count; i++) {
// 獲取手機號碼的的名字
NSString phoneName= (__bridge_transfer NSString)(ABMultiValueCopyLabelAtIndex(phone, i));
// 獲取手機號碼
NSString phoneVaule = (__bridge_transfer NSString)(ABMultiValueCopyValueAtIndex(phone, i));
NSLog(@"==%@,%@",phoneName,phoneVaule);
}
CFRelease(phone);
}
//選中一個聯系人的一個屬性時的方法候調用的方法(如果實現了這個方法選擇聯系人的屬性就會跳出這個頁面,自動退出當前的控制器)。
-
(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
// 在這里面也是對person 這個對像進行操作和,上面的代理操作類似
}
// 點擊取消按鈕會執行的方法
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
NSLog(@"你點擊了取消按鈕");
}