2012-01-22 168 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); 
}