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 获取通讯录的主要内容,如果未能解决你的问题,请参考以下文章

利用AddressBook.framework框架获取iOS系统通讯录数据

IOS 获取系统通讯录中的联系人信息

IOS获取系统通讯录联系人信息

iOS中获取本地通讯录联系人以及汉字首字母排序

iOS获取通讯录 电话号码与姓名

如何获取(提取)iOS系统应用程序的图标,如通讯录应用程序?