Contact is missing some of the required key descriptors in ios

后端 未结 3 1201
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 18:35

I have retrieves all contact by using following method

- (void)getAllContacts:(void(^)(NSArray *array))handler
{
    CNAuthorizationStatus status = [CNContac         


        
相关标签:
3条回答
  • 2021-01-04 19:18

    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];
    
    0 讨论(0)
  • 2021-01-04 19:20

    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()])
    
    0 讨论(0)
  • 2021-01-04 19:34

    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]]];
    
    0 讨论(0)
提交回复
热议问题