views:

154

answers:

3

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?

Thanks!

A: 

You'll have to detect labels with the suffix and prefix. Then do a substring to get the label.

The values you're getting are the correct label of the strings in the address book database. They're just polished up a bit before presentation to the user. That's all.

Giao
A: 

Try this:

+ (NSString *) displayPropertyName:(NSString *) propConst{
    if ([propConst isEqualToString:@"_$!<Anniversary>!$_"]) return @"anniversary";
    if ([propConst isEqualToString:@"_$!<Assistant>!$_"]) return @"assistant";
    if ([propConst isEqualToString:@"_$!<AssistantPhone>!$_"]) return @"assistant";
    if ([propConst isEqualToString:@"_$!<Brother>!$_"]) return @"brother";
    if ([propConst isEqualToString:@"_$!<Car>!$_"]) return @"car";
    if ([propConst isEqualToString:@"_$!<Child>!$_"]) return @"child";
    if ([propConst isEqualToString:@"_$!<CompanyMain>!$_"]) return @"company main";
    if ([propConst isEqualToString:@"_$!<Father>!$_"]) return @"father";
    if ([propConst isEqualToString:@"_$!<Friend>!$_"]) return @"friend";
    if ([propConst isEqualToString:@"_$!<Home>!$_"]) return @"home";
    if ([propConst isEqualToString:@"_$!<HomeFAX>!$_"]) return @"home fax";
    if ([propConst isEqualToString:@"_$!<HomePage>!$_"]) return @"home page";
    if ([propConst isEqualToString:@"_$!<Main>!$_"]) return @"main";
    if ([propConst isEqualToString:@"_$!<Manager>!$_"]) return @"manager";
    if ([propConst isEqualToString:@"_$!<Mobile>!$_"]) return @"mobile";
    if ([propConst isEqualToString:@"_$!<Mother>!$_"]) return @"mother";
    if ([propConst isEqualToString:@"_$!<Other>!$_"]) return @"other";
    if ([propConst isEqualToString:@"_$!<Pager>!$_"]) return @"pager";
    if ([propConst isEqualToString:@"_$!<Parent>!$_"]) return @"parent";
    if ([propConst isEqualToString:@"_$!<Partner>!$_"]) return @"partner";
    if ([propConst isEqualToString:@"_$!<Radio>!$_"]) return @"radio";
    if ([propConst isEqualToString:@"_$!<Sister>!$_"]) return @"sister";
    if ([propConst isEqualToString:@"_$!<Spouse>!$_"]) return @"spouse";
    if ([propConst isEqualToString:@"_$!<Work>!$_"]) return @"work";
    if ([propConst isEqualToString:@"_$!<WorkFAX>!$_"]) return @"work fax";
    return @"";
}
TechZen
+1  A: 

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);
Stephan