I am trying to access and load all contacts on iOS 10; however, my app crashes every time the controller loads. I just converted my project from Swift 2 to Swift 2.3 (it was working on Swift 2). I have also added the Privacy Usage for Contacts in my info.plist, but that did not fix the issue. Here is my code:
I found this from a tutorial online to request for access :
func checkAccessStatus(completionHandler: (accessGranted: Bool) -> Void) {
let authorizationStatus = CNContactStore.authorizationStatusForEntityType(CNEntityType.Contacts)
switch authorizationStatus {
case .Authorized:
completionHandler(accessGranted: true)
case .Denied, .NotDetermined:
self.accessStore.requestAccessForEntityType(CNEntityType.Contacts, completionHandler: { (access, accessError) -> Void in
if access {
completionHandler(accessGranted: access)
} else {
print("access denied")
print(accessError)
}
})
default:
completionHandler(accessGranted: false)
}
}
I keep getting this error: "Optional(Error Domain=CNErrorDomain Code=100 "Access Denied" UserInfo={NSLocalizedDescription=Access Denied, NSLocalizedFailureReason=This application has not been granted permission to access Contacts.})"
The code above is a snipper from my controller where the error is happening. I am attempting to request access but it keeps failing. Are there additional steps I need to do to receive access to the contacts? I am not getting a popup box asking for permission when I load the page (even though I added the privacy bit in the info.plist for contacts usage). I have also checked the privacy settings & looked to see if I had disabled the app's access to contacts; however, it is not showing. I appreciate any help, thank you!
Update: I found this question, which seems to be a similar problem (though it is iOS 9) here. How do I delete my info.plist and make a new one?