0

I'm fetching contacts from address book but popup not show to ask permission to access contacts. it automatically denied but when i try same code in a demo then it run properly but it ddi not run in my app. I have read many articles but i did not get any solution. Is i'm missing something in plist or settings.

CNContactStore * contactStore = [[CNContactStore alloc]init];

    if ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] == CNAuthorizationStatusNotDetermined) {
        [contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * __nullable error) {

            if (granted==YES)
            {


            }
            else
            {
                NSLog(@"Error");
            }
        }];
    }

or second methods

 CFErrorRef error = nil;
    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {

    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error)
     {
         if (error)
         {
             NSLog(@"error %@", error);
         }
         else if (granted)
         {

}
         CFRelease(addressBook);
     });

    }
Vikash Rajput
  • 445
  • 5
  • 21

3 Answers3

3

I also had this issue today, and I deleted some keys from Info.plist:

<key>CFBundleDisplayName</key>
<string></string>
<key>LSApplicationCategoryType</key>
<dict/>
<key>CFBundleGetInfoString</key>
<string></string>

It works now. wired case.

Cody
  • 4,353
  • 4
  • 39
  • 42
1

Entering my application's name in the info.plist "Bundle display name" key allowed my app to show a request for access to my contacts.

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
0

I had the same issue. Cody's answer led me to try this which worked for me.

In your Info.plist, for the key "Bundle display name", make sure it's not an empty string. This name is used when prompting for the contacts permission.

vooooo
  • 1
  • 1