CNContact-CNPhoneNumber

Using ABAddressBook; retrieving a phone number returns a string with the localized phone number formatting or user formatting retained. i.e. as it was formatted in the Contacts app.


The new CNContact API returns a phone number stripped of all formatting, yet there appears to be no "Phone number formatter" similar to CNPostalAdressFormatter (localization for display of addresses), CNContactFormatter (localization for display of names).


For example: A number in the iPhone simulator's supplied Contacts is displayed in the Contacts app as "(888) 555-5512" and using the deprecated ABAddressBook framework can be retrieved as "(888) 555-5512" …but retrieved using the CNContact API the same number is handed to me as "8885555512".


Is there a way to localize or retrieve the formatting of phone numbers from the CNContact API that I'm overlooking?

If not, given that the Contact app does have the concept of localized phone number formatting (and displays its phone numbers formated), what is the thinking behind not providing phone number formatting in CNContact?

Thanks, I did have a look at NSDataDetector before I posted, but couldn't see how this would help me with this specific problem.


Can you elaborate a bit on your answer?


Just to be clear;

CNContact returns a phone number

somePhoneNumber: CNPhoneNumber

and

somePhoneNumber.stringValue

always returns the number as a string with all formatting stripped out in the form "8885555512"


I want to display that number to the user with the same formatting that they see it in their Contact.app


TIA.

Formatting the Phone Numbers:


You can just use this for a localized string of the iPhone number for example: (look up the other phone constant string keys and for each one call this method before you fetch the contacts). The results will be localized.


CNContact.localizedStringForKey(CNLabelPhoneNumberiPhone)


Other contact phone keys:

CNLabelPhoneNumberiPhone
CNLabelPhoneNumberMobile
CNLabelPhoneNumberMain
CNLabelPhoneNumberHomeFax
CNLabelPhoneNumberWorkFax
CNLabelPhoneNumberOtherFax
CNLabelPhoneNumberPager


If this solves your issue please mark the link below otherwise update the thread.

Many Thanks - However my issue appers to be fixed in the release version of iOS9 so I gusess it was a bug. ie. somePhoneNumber.stringValue now returns a string as formatted in the contact book. My original test code was un-touched.

CNContact-CNPhoneNumber
 
 
Q