首页 > 代码库 > iOS 获取通讯录
iOS 获取通讯录
1.导入ContactsUI.framework Contacts.framework
2.在ViewController.m中导入
#import <Contacts/Contacts.h>
#import <ContactsUI/ContactsUI.h>
3.在ViewController.m中运行以下代码
//获取通讯录
self.phoneArr = [[NSMutableArray alloc] init];
CNContactStore *store = [[CNContactStore alloc] init];
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactPhoneticFamilyNameKey, CNContactPhoneNumbersKey]];
[store enumerateContactsWithFetchRequest:request error:nil usingBlock:^(CNContact * _Nonnull contact, BOOL * _Nonnull stop) {
NSLog(@"。。。。。%@", contact.phoneNumbers);
NSArray *phoneNums = contact.phoneNumbers;
for (CNLabeledValue *labledValue in phoneNums) {
CNPhoneNumber *phoneNumber = labledValue.value;
NSString *phoneValue = http://www.mamicode.com/phoneNumber.stringValue;
[self.phoneArr addObject:phoneValue];
}
}];
iOS 获取通讯录