We’re growing an iOS app that makes use of the native contact search performance on iOS gadgets. Nonetheless, we’re encountering a problem the place some customers are unable to seek for native contacts utilizing the contact’s title or quantity enter.
Beneath is a code snippet from our challenge that makes use of the enumerateContacts()
API from CNContactStore()
:
public func searchContacts(question: String, completion: @escaping SearchContactHandler) {
let keysToFetch: [CNKeyDescriptor] = [
CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
CNContactPhoneNumbersKey as CNKeyDescriptor,
]
DispatchQueue.world(qos: .userInitiated).async { [store] in
do {
var contacts: [PhoneContactInfo] = []
strive retailer.enumerateContacts(with: CNContactFetchRequest(keysToFetch: keysToFetch)) { contact, _ in
contacts.append(contentsOf: PhoneContactsFilter.filter(contact: contact, question: question))
}
completion(.success(contacts))
} catch {
completion(.failure(error))
}
}
}
We’ve additionally tried to make use of the unifiedContacts()
API from CNContactStore()
:
let storeContacts = strive self.retailer.unifiedContacts(
matching: searchNamePredicate,
keysToFetch: self.keysToFetch
)
var contacts: [PhoneContactInfo] = []
strive retailer.enumerateContacts(with: CNContactFetchRequest(keysToFetch: keysToFetch)) { contact, _ in
contacts.append(contentsOf: PhoneContactsFilter.filter(contact: contact, question: question))
storeContacts.forEach { contact in
contacts.append(contentsOf: PhoneContactsFilter.filter(contact: contact, question: question))
}
We’ve thought-about the next elements:
- We all the time request native contact permission at any time when the search is required.
searchContacts
shall be executed after permission is.licensed
. - The implementation particulars of
PhoneContactsFilter.filter(contact: contact, question: question)
may be thought-about appropriate trigger it really works in most of customers. - We examined one of many affected customers and located that they had been capable of seek for native contacts with the identical code utilizing a distinct app bundle ID (staging vs manufacturing).
We might recognize any insights on why some customers are unable to seek for native contacts with the enter of the contact’s title or quantity.