简体   繁体   English

iOS9联系人框架缺少电话号码标签?

[英]iOS9 Contacts Framework missing phone number labels?

I am implementing a new iOS application that is only supporting iOS9+. 我正在实现一个仅支持iOS9 +的新iOS应用程序。 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. CNPhoneNumber定义了不同类型电话号码的标签,但是与实际的iOS联系人屏幕相比,它包含的类型列表要小得多。 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. 例如,在我的iPhone上,我可以为联系人添加“工作”类型以外的号码,但SDK中没有相应的CNLabelPhoneNumberWork标签。 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? 除非我将Apple的“ $ !! $ ”字符串硬编码到我的应用程序中,否则联系人可能会有很多无法识别的数字?

As far as I can tell CNPhoneNumber only provides these labels: 据我所知,CNPhoneNumber仅提供以下标签:

@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 但是,如Apple的文档所述:电话号码标签

These constants are predefined labels that can be used in a CNLabeledValue object having a CNPhoneNumber value. 这些常量是预定义的标签, 可以在具有CNPhoneNumber值的CNLabeledValue对象中使用。

You would still get a NSString* (note not enum ) from CNLabeledValue label property, and it would contain whatever appears in the Contacts. 您仍然会从CNLabeledValue label属性中获得NSString* (注意不是 enum ),它将包含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?" 对于“除非我将Apple的“ $ !! $”字符串硬编码到我的应用程序中,否则联系人可能会有很多无法识别的数字?“

The answer would be NO 答案是否定的

phoneNumbers of a CNContact : phoneNumbers一个的CNContact

This property is an array of CNLabeledValue objects, each of which has a label and a CNPhoneNumber value. 此属性是CNLabeledValue对象的数组,每个对象都有一个标签和一个CNPhoneNumber值。

When you iterate though it, .label would give you something like 'Work', and .value would give the actual number you want. 当您进行迭代时, .label会给您类似“工作”的信息,而.value会给您想要的实际数字。

EDIT: 编辑:

Interestingly, in Contacts Framework Reference , there appears CNLabelHome and CNLabelWork , which appears to be "Generic Labels" constants in CNLabeledValue Class. 有趣的是,在Contacts Framework Reference中 ,出现了CNLabelHomeCNLabelWork ,它们似乎是CNLabeledValue类中的“通用标签”常量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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