CNContactProperty
CNContactProperty represents the item the user selected in a contact's details: which value of which field of which contact. For example, if the user taps Alex Chen's mobile number, it says the contact is Alex Chen, the field is phone numbers, and the value is that number.
The picker hands it to the App through its contactpropertyselect event.
Install @nacrejs/contacts first; see CNContactPickerViewController for how.
Inheritance: EventTarget → NSObject → CNContactProperty
Constructor
Can't be created with new; it only comes from contactProperty on the contactpropertyselect event.
new CNContactProperty() throws TypeError: Illegal constructor: CNContactProperty is a read-only value handed over by CNContactPickerViewController, not created by new.
Instance properties
All are read-only. Also inherits the properties of NSObject.
| Property | Description |
|---|---|
contact read-only | The contact this item belongs to |
key read-only | The field name, such as 'phoneNumbers' |
value read-only | The selected value |
identifier read-only | When the selection is one entry of a labeled value, that entry's identifier |
label read-only | When the selection is one entry of a labeled value, that entry's raw label |
Examples
/// <reference types="@nacrejs/types" />
/// <reference types="@nacrejs/contacts" />
const picker = new CNContactPickerViewController();
picker.addEventListener('contactpropertyselect', (event) => {
const property = event.contactProperty;
const value = property.value;
const text = value instanceof CNPhoneNumber ? value.stringValue : value;
console.log(property.key, text);
});Effect: when the user taps a phone number in the details, logs phoneNumbers 555-0100; when they tap an email address, logs emailAddresses alex@example.com; when they tap a field such as an address or birthday, logs the field name and null.
Corresponding iOS API
| ObjC | JS |
|---|---|
property.contact, key, value, identifier, label | Same |
See also
contactpropertyselect: where it comes fromCNContact: the type ofcontactCNLabeledValue: the entry thatidentifierandlabelrefer to