Skip to content

Instantly share code, notes, and snippets.

@SarahAlsharif
Created August 7, 2020 01:12
Show Gist options
  • Save SarahAlsharif/6aa8a6ef16c225d80192786b902c5d43 to your computer and use it in GitHub Desktop.
Save SarahAlsharif/6aa8a6ef16c225d80192786b902c5d43 to your computer and use it in GitHub Desktop.
func requestAccess() {
let store = CNContactStore()
switch CNContactStore.authorizationStatus(for: .contacts) {
case .authorized:
self.getContacts()
case .denied:
store.requestAccess(for: .contacts) { granted, error in
if granted {
self.getContacts()
}
}
case .restricted, .notDetermined:
store.requestAccess(for: .contacts) { granted, error in
if granted {
self.getContacts()
}
}
@unknown default:
print("error")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment