系统通讯录的获取

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

框架:AddressBook、AddressBookUI

ABPeoplePickerNavigationControllerDelegate

ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.peoplePickerDelegate = self;
[self presentViewController:peoplePicker animated:YES completion:nil];



#pragma mark - ABPeoplePickerNavigationControllerDelegate协议方法
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
    
    ABMultiValueRef valuesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFIndex index = ABMultiValueGetIndexForIdentifier(valuesRef,identifier);
    //电话号码
    CFStringRef telValue = ABMultiValueCopyValueAtIndex(valuesRef,index);
    
    //读取firstname
    //获取个人名字(可以通过以下两个方法获取名字,第一种是姓、名;第二种是通过全名)。
    //第一中方法
    //    CFTypeRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
    //    CFTypeRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
    //    //姓
    //    NSString * nameString = (__bridge NSString *)firstName;
    //    //名
    //    NSString * lastString = (__bridge NSString *)lastName;
    
    //第二种方法:全名
    CFStringRef anFullName = ABRecordCopyCompositeName(person);
    [self dismissViewControllerAnimated:YES completion:^{
        
        NSLog(@"name %@,phone %@",anFullName,(__bridge NSString *)telValue);
        //去掉-
        NSLog(@"%@",[(__bridge NSString *)telValue stringByReplacingOccurrencesOfString:@"-" withString:@""]);
    }];
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
    return NO;
}
//Cancel 按钮
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}