Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display CFStringType? Like kABHomeLabel

I know that NSString and CFString are toll-bridge, they can convert in such a way.

CFStringRef cfStr;
NSString* anStr=(NSString*)cfStr;

however,when I convert string in such a case when dealing addressbook

NSString* homeLabel=(NSString*)kABWorkLabel;

then homeLabel is "_$!<Work>!$_"; the other pre-defined CFStringRef in the addressbook property is the same.

in my program, I want to get both the label and the label item's info.

NSString* label=ABMultiValueCopyLabelAtIndex(multi,i);

so how to correctly get the string of the label?

like image 417
xiaozi Avatar asked Apr 03 '10 10:04

xiaozi


1 Answers

Tried using ABAddressBookCopyLocalizedLabel?

Something like:

  ABAddressBookRef ab = ABAddressBookCreate();
  ABRecordID personID = <someid>;
  CFIndex phoneNumberIndex = <anIndexFromSomewhere>;
  ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab, personID);

  CFStringRef name = ABRecordCopyCompositeName(person);
  ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
  CFStringRef number = ABMultiValueCopyValueAtIndex(phoneNumbers, phoneNumberIndex);
  CFStringRef label = ABMultiValueCopyLabelAtIndex(phoneNumbers, phoneNumberIndex);
  CFStringRef localizedLabel = ABAddressBookCopyLocalizedLabel(label);

  NSLog(@"Person: %@", name);
  NSLog(@"%@ : %@", localizedLabel, number);

  CFRelease(label);
  CFRelease(localizedLabel);
  CFRelease(number);
  CFRelease(phoneNumbers);
  CFRelease(name);
  CFRelease(ab);
like image 116
Stephan Avatar answered Sep 21 '22 03:09

Stephan