Oc 通讯录的使用
鏈接】iPhone通訊錄聯系人的增加、刪除、修改的操
http://blog.csdn.net/yongyinmg/article/details/26376905
【鏈接】CNContact對通訊錄的基本使用(第二篇)
http://www.cnblogs.com/lantu1989/p/5469346.html
首先在工程里導入ContactsUI.framework和Contacts.framework兩個框架
#import <ContactsUI/ContactsUI.h> @interface ViewController ()<CNContactPickerDelegate>@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];} -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{//iOS 10// AB_DEPRECATED("Use CNContactPickerViewController from ContactsUI.framework instead")CNContactPickerViewController * contactVc = [CNContactPickerViewController new];contactVc.delegate = self;[self presentViewController:contactVc animated:YES completion:^{}]; } #pragma mark - 用戶點擊聯系人獲取方法 兩個方法都寫只調用此方法 -(void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact{// NSLog(@"contact : %@",contact);// 姓氏 名字NSLog(@"name:%@%@",contact.familyName,contact.givenName);//公司名NSLog(@"公司: %@",contact.organizationName);//獲取通訊錄某個人所有電話并存入數組中 需要哪個取哪個NSMutableArray * arrMPhoneNums = [NSMutableArray array];for (CNLabeledValue * labValue in contact.phoneNumbers) {NSString * strPhoneNums = [labValue.value stringValue];NSLog(@"所有電話是: %@",strPhoneNums);[arrMPhoneNums addObject:strPhoneNums];}//所有郵件地址數組NSMutableArray * arrMEmails = [NSMutableArray array];for (CNLabeledValue * labValue in contact.emailAddresses) {NSLog(@"email : %@",labValue.value);[arrMEmails addObject:labValue.value];}[picker dismissViewControllerAnimated:YES completion:nil]; }#pragma mark - 用戶點進去獲取屬性調用方法 例如從通訊錄選擇聯系人打電話兩個方法都寫只調用上面方法 - (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperty:(CNContactProperty *)contactProperty{// NSLog(@"contactProperty : %@",contactProperty);// NSLog(@"contact : %@",contactProperty.contact);// NSLog(@"key : %@",contactProperty.key);// [[UIApplication sharedApplication] openURL:url];// NSLog(@"identifier : %@",contactProperty.identifier);// NSLog(@"label : %@",contactProperty.label);//獲得點擊的屬性,在此進行處理...NSLog(@"value : %@",[contactProperty.value stringValue]);[picker dismissViewControllerAnimated:YES completion:nil]; }- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker{[picker dismissViewControllerAnimated:YES completion:nil]; }- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated. }@end總結
- 上一篇: __doPostBack简单的使用方法
- 下一篇: html判断是否在页面,html判断当前