iOS10 获取系统通讯录新方法

#import <ContactsUI/ContactsUI.h>

遵循代理

CNContactPickerDelegate

调用通讯录 
如果在iOS10的机器上调用以前的ABPeoplePickerNavigationController老方法将直接崩溃.

-(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:^{
    }];
}

选择完成代理回调

-(void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact{
    NSLog(@"name:%@%@",contact.familyName,contact.givenName);
    CNLabeledValue * labValue = [contact.phoneNumbers lastObject];
    NSLog(@"phone:%@",[labValue.value stringValue]);
}

取消选择回调

- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker{
    [picker dismissViewControllerAnimated:YES completion:nil];
}
posted @ 2016-09-20 16:47  溺水的小小鱼  阅读(2195)  评论(0编辑  收藏  举报