ios – 使用Contacts框架获取本地化的电话标签

ios – 使用Contacts框架获取本地化的电话标签,第1张

概述我正在尝试使用CNContact.My获取本地化的电话标签值到目前为止: NSError *error = nil; CNContactFetchRequest *fetchRequest =[[CNContactFetchRequest alloc] initWithKeysToFetch:keysToFetch]; [addressBook enumerateContact 我正在尝试使用CNContact.My获取本地化的电话标签值到目前为止:
NSError *error = nil;    CNContactFetchRequest *fetchRequest =[[CNContactFetchRequest alloc] initWithKeysToFetch:keysToFetch];    [addressBook enumerateContactsWithFetchRequest:fetchRequest error:&error usingBlock:^(CNContact * _Nonnull contact,BOol * _Nonnull stop) {       CNLabeledValue *phoneNumberValue = contact.phoneNumbers.firstObject;       Nsstring *label = phoneNumberValue.label;       NSLog(@"Phone Label: %@",label); //Logs value like _$!<Home>!$_       CNPhoneNumber *phoneNumber = phoneNumberValue.value;       Nsstring *phoneNumberString = phoneNumber.stringValue;       NSLog(@"Phone No: %@",phoneNumberString);    }];

问题是手机标签返回的原始值如_ $!< Home>!$_,_ $!< Mobile>!$_.但我需要像Home,Mobile这样的纯文本.有什么办法可以使用Contact框架获取本地化值.我不想使用Addressbook,因为它在iOS 9中已被弃用.

解决方法 使用CNLabeledValues类方法localizedStringForLabel:并传递标签

例:

CNLabeledValue *phoneNumberValue = contact.phoneNumbers.firstObject;   Nsstring *label = phoneNumberValue.label;   label = [CNLabeledValue localizedStringForLabel:label];   NSLog(@"Phone Label: %@",label); //Logs value like _$!<Home>!$_
总结

以上是内存溢出为你收集整理的ios – 使用Contacts框架获取本地化的电话标签全部内容,希望文章能够帮你解决ios – 使用Contacts框架获取本地化的电话标签所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1109207.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存