#import <ContactsUI/ContactsUI.h>
CNContactPickerDelegate
- 调用通讯录
- 如果在iOS10的机器上调用以前的ABPeoplePickerNavigationController老方法将直接崩溃.
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
CNContactPickerViewController * contactVc = [CNContactPickerViewController new];
contactVc.delegate = self;
[self presentViewController:contactVc animated:YES completion:^{
}];
}
#pragma mark - 用户点击联系人获取方法 两个方法都写只调用此方法
-(void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)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(@"value : %@",[contactProperty.value stringValue]);
[picker dismissViewControllerAnimated:YES completion:nil];
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker{
[picker dismissViewControllerAnimated:YES completion:nil];
}