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框架获取本地化的电话标签所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)