1. 程式人生 > >iOS10 獲取通訊錄 最簡單的方法分享

iOS10 獲取通訊錄 最簡單的方法分享

1先匯入標頭檔案

#import <ContactsUI/ContactsUI.h>

2遵循代理

<CNContactPickerDelegate>

3 開始方法

CNContactPickerViewController * contactVc = [CNContactPickerViewControllernew];

        contactVc.delegate = self;

        [selfpresentViewController:contactVc animated:YEScompletion:^{

        }];

4下面是代理方法

-(void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact{

NSLog(@"name:%@%@",contact.familyName,contact.givenName);

CNLabeledValue * labValue = [contact.phoneNumberslastObject];

NSLog(@"phone:%@",[labValue.valuestringValue]);

}

//取消選擇回撥

- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker{

    [picker dismissViewControllerAnimated:YEScompletion:nil];

}