iOS10 獲取通訊錄 最簡單的方法分享
阿新 • • 發佈:2019-02-11
1先匯入標頭檔案
#import <ContactsUI/ContactsUI.h>
2遵循代理<CNContactPickerDelegate>
3 開始方法
CNContactPickerViewController * contactVc = [CNContactPickerViewControllernew];
contactVc.delegate = self;
[selfpresentViewController:contactVc animated:YEScompletion:^{
}];
-(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];
}