标签:
2. AddressBook.framework
1、生成联系人控制器
1 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 2 { 3 // 1.创建选择联系人的界面 4 ABPeoplePickerNavigationController *ppnc = [[ABPeoplePickerNavigationController alloc] init]; 5 6 // 2.设置代理 7 ppnc.peoplePickerDelegate = self; 8 9 // 3.弹出选择联系人界面 10 [self presentViewController:ppnc animated:YES completion:nil]; 11 }
2、代理方法
1)点击联系人时调用
1 // 系统注释:Called after a person has been selected by the user. 2 // 直译:一个人被选中后被称为用户后调用 3 // 意译:选中某一个联系人的时候,会执行该代理方法 4 // 方法:如果实现了该方法,那么就不会进入联系人的详细界面 5 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person NS_AVAILABLE_IOS(8_0) { 6 7 // 1.获取选中联系人的姓名(姓lastname和名firstname) 8 CFStringRef firstname = ABRecordCopyValue(person, kABPersonFirstNameProperty); 9 CFStringRef lastname = ABRecordCopyValue(person, kABPersonLastNameProperty); 10 NSString *firstName = (__bridge_transfer NSString *)(firstname); 11 NSString *lastName = (__bridge_transfer NSString *)(lastname); 12 NSLog(@"%@ %@", firstName, lastName); 13 14 // 2.获取联系人的电话号码 15 ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty); 16 CFIndex count = ABMultiValueGetCount(phones); 17 for (CFIndex i = 0; i < count; i++) { 18 NSString *phoneLabel = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex(phones, i); 19 NSString *phoneValue = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phones, i); 20 NSLog(@"label : %@ value : %@", phoneLabel, phoneValue); 21 } 22 23 // 3.释放不再使用的对象 24 CFRelease(phones); 25 26 }
2)点击联系人属性时调用
1 // Called after a property has been selected by the user. 2 // 直译:一个属性被用户选定后调用。 3 // 意译:选中某一个联系人的属性的时候,会执行该代理方法 4 // 方法:如果实现了该方法,那么选中一个联系人的属性时,就会推出控制器.不会进入下一个页面 5 // 参数: arg1:property 选中的属性 identifier : 每一个属性都由一个对应标示 6 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier NS_AVAILABLE_IOS(8_0) { 7 8 NSLog(@"选择了某一个联系人的某一个属性"); 9 10 }
3)点击取消按钮调用
1 // Called after the user has pressed cancel. 2 // 直译:取消被选中后被称为用户后调用 3 // 意译:选中取消按钮的时候,会执行该代理方法 4 - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker { 5 6 NSLog(@"用户点击了取消按钮"); 7 8 }
未完待续~~~~~
by:Coder丶PSS
标签:
原文地址:http://www.cnblogs.com/PSSSCode/p/5495506.html