Contact is missing some of the required key descriptors in ios

I have retrieves all contact by using following method

- (void)getAllContacts:(void(^)(NSArray *array))handler
{
    CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];

    if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusDenied)
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"This app previously was refused permissions to contacts; Please go to settings and grant permission to this app so it can use contacts" preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alert animated:TRUE completion:nil];
        return;
    }

    CNContactStore *store = [[CNContactStore alloc] init];
    [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {

        // make sure the user granted us access
        if (!granted)
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                // user didn't grant access;
                // so, again, tell user here why app needs permissions in order  to do it's job;
                // this is dispatched to the main queue because this request could be running on background thread
            });
            return;
        }

        // build array of contacts
        NSMutableArray *contacts = [NSMutableArray array];

        NSError *fetchError;
        CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]]];

        BOOL success = [store enumerateContactsWithFetchRequest:request error:&fetchError usingBlock:^(CNContact *contact, BOOL *stop) {

            [contacts addObject:contact];
        }];

        if (!success)
        {
            NSLog(@"error = %@", fetchError);
            return;
        }
        handler((NSArray *)contacts);
   }];

}

  • Xcode 7.1 beta 2- Disable ATS
  • error after updating the Xcode to 7.0
  • iOS Contacts How to Fetch contact by phone Number
  • How to change date picker date to a NSDate type but with zero seconds
  • iOS 9 UITableView separators insets (significant left margin)
  • wkWebView fails to play local audio
  • And contacts are listed in tableview. Now I am trying to select particular contact from “,

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CNContact *contact = [arrContacts objectAtIndex:indexPath.row];
        NSArray *keys = @[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]];
        CNContactViewController *contactController = [CNContactViewController viewControllerForContact:contact];
        contactController.delegate = self;
        contactController.allowsEditing = YES;
        contactController.allowsActions = YES;
        contactController.displayedPropertyKeys = keys;
        [self.navigationController pushViewController:contactController animated:TRUE];
    }
    

    But it says

    Contact 0x7fc732654530 is missing some of the required key descriptors

    Please help me to solve it, if anyone know. Thanks.

    3 Solutions Collect From Internet About “Contact is missing some of the required key descriptors in ios”

    Add “CNContactViewController.descriptorForRequiredKeys” at the end of your keysToFetch array.

    Worked for me after I did that.

    Example:

    NSArray *keysToFetch = @[CNContactIdentifierKey, CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactImageDataAvailableKey, CNContactImageDataKey, CNContactViewController.descriptorForRequiredKeys];
    

    Change you line

     CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]]];
    

    with

     CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName],[CNContactViewController descriptorForRequiredKeys]]];
    

    and some one use it in swift then add like

    let request:CNContactFetchRequest
    request = CNContactFetchRequest(keysToFetch: [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactMiddleNameKey, CNContactEmailAddressesKey,CNContactPhoneNumbersKey,CNContactViewController.descriptorForRequiredKeys()])
    

    You need to add [CNContactViewController descriptorForRequiredKeys] as an array of keysToFetch you have to pass in your CNContactFetchRequest.

    Example:

    CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName], [CNContactViewController descriptorForRequiredKeys]]];