1

連絡先を表形式で表示するには?

CNContactStore iOS 9 経由で連絡先を取得しました。

- (void) getContacts {
    CNContactStore *store = [[CNContactStore alloc] init];
    [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted == YES) {
            //keys with fetching properties
            NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey,CNContactImageDataKey];
            NSString *containerId = store.defaultContainerIdentifier;
            NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
            NSError *error;
            NSArray *cnContactsarray = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];   
            if (error) {
                NSLog(@"error fetching contacts %@", error);
                        }
            else {
                    for (CNContact *contact in cnContactsarray) {
                    //store all the contacts as per your requirement
                    NSLog(@"Name       :     %@",contact.givenName);
                    NSLog(@"Id         :     %@",contact.identifier);//the contact id which you want
                        [_ContactsCN addObject:contact];
                                  }


            }
            NSLog(@"array %@",_ContactsCN);
        }
    }];
}

どんな助けでも大歓迎です。

4

1 に答える 1