码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 获取通讯录

时间:2016-09-18 13:31:30      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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 获取通讯录

标签:

原文地址:http://www.cnblogs.com/zhangxueke/p/5880977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!