Last active
April 4, 2023 16:03
-
-
Save arslanbilal/b95e56fac36445dacee4131e11a7d6d0 to your computer and use it in GitHub Desktop.
ContactsUI select contact property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ContactsUI | |
class ExampleViewController: UIViewController { | |
private func dispayContacts() { | |
let contactPicker = CNContactPickerViewController() | |
contactPicker.delegate = self | |
contactPicker.displayedPropertyKeys = [CNContactGivenNameKey, CNContactPhoneNumbersKey] | |
contactPicker.predicateForEnablingContact = NSPredicate(format: "phoneNumber.@count > 0") | |
contactPicker.predicateForSelectionOfContact = NSPredicate(value: false) | |
contactPicker.predicateForSelectionOfProperty = NSPredicate(format: "key == 'phoneNumbers'") | |
self.present(contactPicker, animated: true) | |
} | |
} | |
extension ExampleViewController: : CNContactPickerDelegate { | |
func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) { | |
if contactProperty.key == "phoneNumbers", | |
let phoneNumber = contactProperty.value as? CNPhoneNumber { | |
// contactProperty.contact (the selected contact) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment