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];

        }

    }];

posted @ 2016-09-18 11:31  花落冉溪何处归  阅读(315)  评论(0编辑  收藏  举报