简体   繁体   中英

kABAuthorizationStatusDenied when i try to access contacts from the iphone for my app?

I have an app which is invisible and runs in the background on iPhone. App wants to access contacts from the iPhone but not getting that due to kABAuthorizationStatusDenied. Here is the code for accessing the contacts.

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
      if (granted) {
          // access has been granted.
      } else {
          // User denied access
      }
    });
  }
  else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // The user has previously given access
  }
  else {
    // The user has previously denied access
  }

It always runs the last else part which is //The user has previously denied access. It means that user has explicitly denied access to contacts. what is the solution? I have tried to Reset Location & Privacy in Settings --> General --> Reset but still getting in the else part which is user has denied access.

Specifications:
iPhone: 5s
iOS : 7.1

Steps:

iOS 8+

  1. Settings -> Select Your App Name -> Privacy -> Enable permission for Contacts app.

iOS 7

  1. Settings -> Privacy -> Contacts -> Select Your App name -> Enable permission

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM