0

I integrated the Contacts framework in my app and the app stays authorized to access the users contacts but now I am looking for a way to remove the authorization if the user decides to do so. I am not finding a method that does that, does anyone have an idea? Thanks in advance.

This is the authorization method on my AppDelegate, it always returns accessGranted = true

    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 {
                if authorizationStatus == CNAuthorizationStatus.denied {
                    DispatchQueue.main.async(execute: { () -> Void in

                    })
                }
            }
        })

    default:
        completionHandler(false)
    }
}

And this is the code on my ViewController where I check if the user is authorized and ask for their authorization in case they aren't.

   AppDelegate.getAppDelegate().requestForAccess { (accessGranted) -> Void in
        if accessGranted {
         self.iCloudConnected = true
         self.fetchContacts()
        }else{
        self.iCloudConnected = false
        }
        self.tableView.reloadData()
    }
rmaddy
  • 314,917
  • 42
  • 532
  • 579
JP Aquino
  • 3,946
  • 1
  • 23
  • 25
  • 1
    If the user wants to remove authorization, they do that in settings, where they control their privacy settings for all of their apps. You don't have to do anything in your code. – Rob Oct 31 '16 at 15:40
  • Even more, you can't do anything in code other than offer the user a chance to go to the app's settings page. – rmaddy Oct 31 '16 at 16:14

0 Answers0