in my app I am using CNContactPickerViewController for getting contacts. User can select multiple contacts so I implemented following delegate methods.
func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
var tempContacts = [Contact]()
contacts.forEach { (contact) in
if let phoneNumber = contact.phoneNumbers.first {
let contact = Contact(name: "\(contact.givenName) \(contact.familyName)" , phoneNumber: "\(phoneNumber.value.stringValue)")
tempContacts.append(contact)
}
}
selectedContacts = tempContacts
_ = Contact.save(contacts: selectedContacts)
}
func contactPickerDidCancel(_ picker: CNContactPickerViewController) {
print("Cancel contact picker")
}
However, some users are complaining about not able to see and select if contact has more than one phone number. Is it possible to show contacts that have multiple numbers?
You're only using the first phone number of a contact:
What if you map all the phone numbers to an array of contacts using the
mapmethod: