Oc 通讯录的使用

来源:互联网 发布:淘宝人生笔趣阁 编辑:程序博客网 时间:2024/05/20 06:08

链接】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