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()
}