Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CNContactPickerViewController when contact has multiple mails

I'm using a CNContactPickerViewController to let the user select the email of one of his/her contacts

let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
contactPicker.predicateForSelectionOfContact = NSPredicate(format: "emailAddresses.@count > 0")
contactPicker.displayedPropertyKeys = [CNContactNicknameKey, CNContactEmailAddressesKey]

When the contact has only one mail, everything goes well

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {

    if let _mail = contact.emailAddresses.first?.value as String? {
        self.personWasSelected(with: _mail)
    }
}

But sometimes one of the contacts has more than one mail, how can I let the user select on one of those?

like image 713
mtet88 Avatar asked Jan 28 '26 19:01

mtet88


1 Answers

Ok, found the solution by trial-error...

I was implementing both:

func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) {
    if let _mail = contactProperty.value as? String {
        self.personWasSelected(with: _mail)
    }
}

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {

    if let _mail = contact.emailAddresses.first?.value as String? {
        self.personWasSelected(with: _mail)
    }
}

But only the first one should have been implemented

like image 87
mtet88 Avatar answered Jan 31 '26 18:01

mtet88



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!