2012-01-22 171 views
0

我想获取ABPerson对象属性的所有标签名称。例如:记录ABPerson有三个电话号码定义:移动,其他,工作。我使用labelAtIndex方法获取标签名称,但返回的字符串包含用字符包装的所需值$ !! $。而不是只返回“移动”,我得到这些“_ $!<”包装字符。获取ABPerson属性的标签名称

我有以下代码:

//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]);   
} 

在日志中我得到以下几点:

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 

可能有人点我,请我如何可以得到属性标签名称没有特殊字符?

回答

4

据我所知,您需要获得该物品的本地化标签,您需要确保使用正确的参考代码。

// 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); 
}