I am using the Contact framework new to iOS 9 and I cannot figure out how to get the digits from the phoneNumbers key on a CNContact.
Doing an NSLog of the CNContact I get this output:
<CNContact: 0x14f57e680: identifier=1B39B156-A151-4905-9624-
DB117ACFBADC, givenName=John, familyName=Doe,
organizationName=CompanyName, phoneNumbers=(
"<CNLabeledValue: 0x154297a40: identifier=3FEB6B0C-7179-4163-93E6-63C156C2F02B,
label=_$!<Mobile>!$_, value=<CNPhoneNumber: 0x155400e00: countryCode=us,
digits=1234567890>>"
), emailAddresses=(
), postalAddresses=(
)>
I am able to get the keys for givenName and familyName like this:
CNContact *contact;
[contact valueForKey:@"givenName"]
[contact valueForKey:@"familyName"]
How do I get the value for the digits that is under the phoneNumbers key?
CNContact
has the phoneNumbers
property. Use that to get the array of phone numbers for the contact.
CNContact *contact = ...;
NSArray <CNLabeledValue<CNPhoneNumber *> *> *phoneNumbers = contact.phoneNumbers;
CNLabeledValue<CNPhoneNumber *> *firstPhone = [phoneNumbers firstObject];
CNPhoneNumber *number = firstPhone.value;
NSString *digits = number.stringValue; // 1234567890
NSString *label = firstPhone.label; // Mobile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With