问题描述
我想获取ABPerson对象的属性的所有标签名称。例如:record ABPerson有三个电话号码定义:移动,其他,工作。我使用labelAtIndex方法获取标签名称,但返回的字符串包含需要的值包装字符 $ !! $ 。而不是只返回移动我得到这些_ $!<包装字符。
I want to get all label names for properties of ABPerson object. For example: record ABPerson has three phone numbers defined: Mobile, Other, Work. I use labelAtIndex method to get label name but returned string contains needed value wrapped in characters $!!$. Instead of returning just "Mobile" I get these "_$!<" wrap-characters.
我有以下代码:
//person object points to ABPerson record from addressBook
ABMultiValue *phoneNumbers = [person valueForProperty:kABPhoneProperty];
NSUInteger count = [phoneNumbers count];
for (int i = 0; i < count; i++) {
NSLog(@"Phone numbers label: %@ value: %@", [phoneNumbers labelAtIndex:i], [phoneNumbers valueAtIndex:i]);
}
在日志中,我得到以下结果:
In log I get following:
2012-01-23 01:14:04.234 FixMyAddressBook[3667:707] Phone numbers label: _$!<Mobile>!$_ value: +327382738273
2012-01-23 01:14:04.370 FixMyAddressBook[3667:707] Phone numbers label: _$!<Work>!$_ value: +3293829328
有人能指出我,如何获得没有特殊字符的属性的标签名称?
Could someone point me please how can I get label names for properties without special characters?
推荐答案
据我所知,您需要获取该商品的本地化标签,您需要确保使用正确的参考代码。
As far as I'm aware you need to get the localized label for that item, you'll need to make sure you're using the right reference code.
// Grab the right property first
ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
CFIndex phoneNumberCount = ABMultiValueGetCount(phoneNumbers);
for(int k = 0; k < phoneNumberCount; k++)
{
//Get phone number label by iterating across this
CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, k );
CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel );
// converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile"
//do whatever you want to do here
//release your references
CFRelease(phoneNumberLocalizedLabel);
CFRelease(phoneNumberValue);
}
这篇关于获取ABPerson属性的标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!