1.Build Phases -> Link Binary With Libraries 에서
Contacts.framework 추가하기.
2. 코드 작성
-(void)loadContactList {
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if( status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted)
{
NSLog(@"access denied");
}
else
{
//Create repository objects contacts
CNContactStore *contactStore = [[CNContactStore alloc] init];
//Select the contact you want to import the key attribute ( https://developer.apple.com/library/watchos/documentation/Contacts/Reference/CNContact_Class/index.html#//apple_ref/doc/constant_group/Metadata_Keys )
NSArray *keys = [[NSArray alloc]initWithObjects:CNContactGivenNameKey,CNContactFamilyNameKey,CNContactPhoneNumbersKey,CNContactImageDataKey, CNContactImageDataAvailableKey, nil];
// Create a request object
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:keys];
request.predicate = nil;
NSMutableArray *contactArray = [[NSMutableArray alloc] init];
[contactStore enumerateContactsWithFetchRequest:request
error:nil
usingBlock:^(CNContact* __nonnull contact, BOOL* __nonnull stop)
{
// Contact one each function block is executed whenever you get
NSString *phoneNumber = @"";
if( contact.phoneNumbers)
phoneNumber = [[[contact.phoneNumbers firstObject] value] stringValue];
NSLog(@"phoneNumber = %@", phoneNumber);
NSLog(@"givenname = %@", contact.givenName);
NSLog(@"familyname = %@", contact.familyName);
[contactArray addObject:contact];
}];
}
}
'Developer > iOS' 카테고리의 다른 글
[ios]iOS8 UIAlertController Sample (0) | 2016.01.06 |
---|---|
[iOS]iOS9 Sportlight 검색 추가하기 (0) | 2016.01.05 |
[iOS] CGContextSetRGBStrokeColor 색깔 Setting하기 (0) | 2015.12.22 |
웹앱(하이브리드앱)의 앱스토어 통과(검수)하기 위한 기준 (0) | 2015.12.18 |
[iOS] iOS9 App Transport Security 설정법 (2) | 2015.12.17 |