iOS 获取通讯录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = phoneNumber.stringValue;
[self.phoneArr addObject:phoneValue];
}
}];
以上是关于iOS 获取通讯录的主要内容,如果未能解决你的问题,请参考以下文章