The ContactsManager SDK requires permission to access the user’s device contacts. This guide explains how to request and manage contacts access in your app.
Check the current authorization status using the contactsAccessStatus property:
let status =ContactsService.shared.contactsAccessStatusswitch status {case.notDetermined:print("User has not yet been asked for permission")case.authorized:print("Access granted")case.denied:print("Access denied")case.restricted:print("Access restricted")}
Request access to contacts with the requestContactsAccess() method:
let granted =awaitContactsService.shared.requestContactsAccess()if granted {print("Contacts access granted")// Now you can use contacts features}else{print("Contacts access denied")// Handle the denial case}
When access is denied, the SDK provides a SwiftUI alert that guides users to the Settings app:
structContentView:View{var body:someView{VStack{Text("Your content here")}// This will only show when access has been denied.overlay(ContactsService.shared.settingsAlert)}}
You can also check if the settings alert should be shown:
ifContactsService.shared.contactsAccessStatus ==.denied {// Show your custom UI to guide users to settings}