简体   繁体   English

当我尝试通过iPhone为我的应用访问联系人时,kABAuthorizationStatusDenied?

[英]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. 我有一个不可见的应用程序,可在iPhone的后台运行。 App wants to access contacts from the iPhone but not getting that due to kABAuthorizationStatusDenied. 应用希望从iPhone访问联系人,但由于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 iPhone 5S
iOS : 7.1 的iOS:7.1

Steps: 脚步:

iOS 8+ iOS 8以上

  1. Settings -> Select Your App Name -> Privacy -> Enable permission for Contacts app. 设置->选择您的应用程序名称->隐私->启用“联系人”应用程序的权限。

iOS 7 IOS 7

  1. Settings -> Privacy -> Contacts -> Select Your App name -> Enable permission 设置->隐私->联系人->选择您的应用名称->启用权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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