Home / IOS Development / ios – CNContactPickerViewController enables multiple options to be disabled

ios – CNContactPickerViewController enables multiple options to be disabled



I want to enable or disable the selection of multiple contacts based on condition.

I have tried the solution below

func onClickPickContact() {
        let contactPicker = CNContactPickerViewController()
        contactPicker.delegate = self
        contactPicker.displayedPropertyKeys =
            [CNContactGivenNameKey
                , CNContactPhoneNumbersKey]
        self.present(contactPicker, animated: true, completion: nil)
    }

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
        self.txtFieldFirstname.text = contact.givenName
        self.txtFieldLastname.text = contact.familyName
    }

This allows me to select multiple contacts, but I want both cases (single selection or multiple selections based on condition).

Once the above delegated method is added, it is not allowed to select only one contact.

Let me know if anyone knows the solution. Thanks in advance.


Source link