2

I am using Contacts Framework to grab all Contacts from my iPhone to my application. But it is fetching only few contacts. This is the code I have used this code:

//ios 9+
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
    if (granted == YES) {

        NSArray *keys = @[CNContactGivenNameKey,CNContactFamilyNameKey,CNContactPhoneNumbersKey,CNLabelPhoneNumberMobile,CNLabelPhoneNumberMain,CNContactImageDataKey,CNContactIdentifierKey];
        NSString *containerId = store.defaultContainerIdentifier;
        NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
        NSError *error;
        NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];

     }
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
Niharika
  • 1,188
  • 15
  • 37
  • 1
    Check this link: http://stackoverflow.com/questions/32669612/how-to-fetch-all-contacts-record-in-ios-9-using-contacts-framework – Sivajee Battina May 10 '17 at 05:54

1 Answers1

0

try this:

    [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {

        if (granted == YES) {

            NSArray *keys = @[CNContactGivenNameKey,CNContactFamilyNameKey,CNContactPhoneNumbersKey,CNLabelPhoneNumberMobile,CNLabelPhoneNumberMain,CNContactImageDataKey,CNContactIdentifierKey];
            NSError *error;
            NSArray *allContainer = [store containersMatchingPredicate:nil error:&error];

            for (CNContainer *container in allContainer) {

                    NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:container.identifier];
                    NSArray *result = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
                    [aryAllContacts addObject:result];
            }
        }
    }];
iOS_MIB
  • 1,885
  • 13
  • 24