iOS:从CNContact获取数字密钥

MSU_Bulldog

我正在使用iOS 9新增的Contact框架,但无法弄清楚如何从CNContact的phoneNumbers键中获取数字。

做一个CNContact的NSLog我得到以下输出:

<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=(
)>

我能够像这样获得给定名称和家庭名称的密钥:

CNContact *contact;
[contact valueForKey:@"givenName"]
[contact valueForKey:@"familyName"]

如何获取phoneNumbers键下的数字值?

rmaddy

CNContactphoneNumbers属性。使用它来获取联系人的电话号码数组。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章