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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With