简体   繁体   中英

iOS9 Contacts Framework missing phone number labels?

I am implementing a new iOS application that is only supporting iOS9+. Thus we are using the new contacts framework to access phone numbers for contacts stored on the device.

CNPhoneNumber defines the labels for different types of phone numbers, but it contains a much smaller list of types than the actual iOS contacts screen. For example on my iPhone I am able to add a number off the type "Work" to a contact but there is no corresponding CNLabelPhoneNumberWork label in the SDK. Am I looking in the wrong place or is this just the way it is? Contacts may have a bunch of numbers that I am unable to identify unless I hardcode Apple's " $!!$ " string to my app?

As far as I can tell CNPhoneNumber only provides these labels:

@available(iOS 9.0, *)
public let CNLabelPhoneNumberiPhone: String
@available(iOS 9.0, *)
public let CNLabelPhoneNumberMobile: String
@available(iOS 9.0, *)
public let CNLabelPhoneNumberMain: String
@available(iOS 9.0, *)
public let CNLabelPhoneNumberHomeFax: String
@available(iOS 9.0, *)
public let CNLabelPhoneNumberWorkFax: String
@available(iOS 9.0, *)
public let CNLabelPhoneNumberOtherFax: String
@available(iOS 9.0, *)
public let CNLabelPhoneNumberPager: String

When I go and add numbers to my contacts the list of available types is much longer.

You are correct in the sense that these should be the only predefined ones for phone number labels.

But, as described in Apple's doc: Phone Number Labels

These constants are predefined labels that can be used in a CNLabeledValue object having a CNPhoneNumber value.

You would still get a NSString* (note not enum ) from CNLabeledValue label property, and it would contain whatever appears in the Contacts. So be prepared you might also get odd input user created by "Custom Labels" option.


For the question of "Contacts may have a bunch of numbers that I am unable to identify unless I hardcode Apple's "$!!$" string to my app?"

The answer would be NO

phoneNumbers of a CNContact :

This property is an array of CNLabeledValue objects, each of which has a label and a CNPhoneNumber value.

When you iterate though it, .label would give you something like 'Work', and .value would give the actual number you want.

EDIT:

Interestingly, in Contacts Framework Reference , there appears CNLabelHome and CNLabelWork , which appears to be "Generic Labels" constants in CNLabeledValue Class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM