Key Takeaways
⛔ Users can now provide limited access to contacts in an app
🔎 Use
ContactAccessButtonto show search results for restricted contacts💽 Use
CNContactStoreto get contact data🔘 Use
ContentAccessPickerto allow users to change access without leaving an app
Presenters
Ada, Software Engineer
Limited Access
Users can now choose to share a limited number of contacts with an app
Access level as well as selected contacts can be changed at any time
Authorization Levels
| Authorization Level | Read | Write |
|---|---|---|
| Full | 🟢 | 🟢 |
| Limited | 🟡 | 🟢 |
| Not Determined | - | - |
| Denied | 🔴 | 🔴 |
Contact Access Picker
Full screen picker that lets users select contacts without leaving an app
Contact Access Button
Allows a full contact picker experience in an app without requiring full access
By selecting the Contact Access Button a user can quickly grant an app access to the contact
Enables restricted contacts to appear in an app’s search results for contacts
Can be used even if an app’s authorization level is “Not Determined”
Using ContactAccessButton
@Binding var searchText: String
@State var authorizationStatus: CNAuthorizationStatus = .notDetermined
var body: some View {
List {
// Show Results for App's Data Store
ForEach(searchResults(for: searchText)) { person in
ResultRow(person)
}
// Show Results from ContactAccessButton
if authorizationStatus == .limited || authorizationStatus == .notDetermined {
ContactAccessButton(queryString: searchText) { identifiers in
let contacts = await fetchContacts(withIdentifiers: identifiers)
dismissSearch(withResult: contacts)
}
}
}
}Accessing Contacts
CNContactStore
Primary way to read/write contact data
Requires authorization to access
Provides notifications when data is changed
Contact Picker View Controller
System UI contact picker
Delivers a snapshot of contact data on when the picker is closed
No authorization is required
Contact Access Picker
System UI contact picker, that allows users to quickly change contact access
Returns contacts to the app as identifiers in
CNContactStore
Which Access Method to Use
| Authorization Level | CNContactPickerViewController | CNContactStore | ContactAccessButton | ContactAccessPicker |
|---|---|---|---|---|
| Full | 🟢 | 🟢 | Not Needed | Not Needed |
| Limited | 🟢 | 🟡 | 🟢 | 🟢 |
| Not Determined | 🟢 | Prompt | 🟢 | 🔴 |
| Denied | 🟢 | 🔴 | 🔴 | 🔴 |
