2017-02-27 100 views
2

我正在使用聯繫人框架。我無法使觸點如果用戶在設置畫面就切換到關閉:Settings app -> App name -> Turn Contacts off拒絕聯繫人訪問(聯繫人框架,iOS)

如果用戶關閉在設置屏幕中的應用程序聯繫權限,是有可能出現一個對話框,允許用戶關聯繫方式?它好像訪問=總是假。一旦用戶通過設置關閉聯繫人,我們是不是允許訪問?

這裏是我的相關代碼:

func requestForAccess(completionHandler: @escaping (_ accessGranted: Bool) -> Void) { 
    let authorizationStatus = CNContactStore.authorizationStatus(for: CNEntityType.contacts) 

    switch authorizationStatus { 
    case .authorized: 
     completionHandler(true) 

    case .denied, .notDetermined: 
     self.contactStore.requestAccess(for: CNEntityType.contacts, completionHandler: { (access, accessError) -> Void in 
      if access { 
       completionHandler(access) 
      } 
      else { 
       //Access is always false 
       if authorizationStatus == CNAuthorizationStatus.denied { 
        completionHandler(false) 
       } 
      } 
     }) 

    default: 
     completionHandler(false) 
    } 
} 
+0

請求訪問的應用程序打開的設置只顯示系統權限提示你第一次做它做到這一點。如果用戶拒絕訪問,那麼您可以顯示一個視圖,告訴他們需要在應用設置中啓用它,以使用您請求訪問的任何功能。 – dan

回答

2

沒有,一旦用戶拒絕訪問聯繫人,你需要引導他們到設置應用。

您可以通過顯示UIAlertViewController,並通過alertAction

UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)