2012-01-22 8 views
0

ABPersonオブジェクトのプロパティのラベル名をすべて取得したいとします。たとえば、レコードABPersonには、Mobile、Other、Workの3つの電話番号が定義されています。 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); 
} 
関連する問題