CNContact Frame work not fetching all contacts(iCloud,Gmail)

Viewed 730

Settings>Contacts>Default Account selected as iCloud and saved a new contact.Then changed Default Account as gmail. CNContactStore not fetching the new saved contact.

 CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
    if (granted == YES)
    {
        NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey,CNContactEmailAddressesKey];
        NSArray * contactContainerArray =  [store containersMatchingPredicate:nil error:nil];
        for(CNContainer * container in contactContainerArray) {
            NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:container.identifier];
            NSError *error;
            NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
}
1 Answers
Related