views:

401

answers:

1

My question concerns markup that surrounds some of the default phone number labels in the Person entries of the Contact list on the iPhone.

I have created an iPhone contact list address book entry for a person, "John Smith" with the following phone number entries:

  • Mobile (604) 123-4567
  • iPhone (778) 123-4567
  • Home (604) 789-4561
  • Work (604) 456-7891
  • Main (604) 789-1234
  • megaphone (234) 567-8990

Note that the first five labels are default labels provided by the Contacts application and the last label, "megaphone", is a custom label.

I wrote the following method to retrieve and display the labels and phone numbers for each person in the address book:

-(void)displayPhoneNumbersForAddressBook {
    ABAddressBookRef book = ABAddressBookCreate();
    CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(book);
    ABRecordRef record = CFArrayGetValueAtIndex(people, 0);
    ABMultiValueRef multi = ABRecordCopyValue(record, kABPersonPhoneProperty); 
    NSLog(@"---------" );
    NSLog(@"displayPhoneNumbersForAddressBook" );

    CFStringRef label, phone;
    for (CFIndex i = 0; i < ABMultiValueGetCount(multi); ++i) {
            label = ABMultiValueCopyLabelAtIndex(multi, i);
            phone = ABMultiValueCopyValueAtIndex(multi, i);
            NSLog(@"label: \"%@\"     number: \"%@\"", (NSString*)label, (NSString*)phone);
            CFRelease(label);
            CFRelease(phone);
    }
    NSLog(@"---------" ); 
    CFRelease(multi);
    CFRelease(people);
    CFRelease(book);
}

and here is the output for the address book entry that I entered:

2010-03-08 13:24:28.789 test2m[2479:207] ---------
2010-03-08 13:24:28.789 test2m[2479:207] displayPhoneNumbersForAddressBook
2010-03-08 13:24:28.790 test2m[2479:207] label: "_$!<Mobile>!$_"     number: "(604) 123-4567"
2010-03-08 13:24:28.790 test2m[2479:207] label: "iPhone"     number: "(778) 123-4567"
2010-03-08 13:24:28.791 test2m[2479:207] label: "_$!<Home>!$_"     number: "(604) 789-4561"
2010-03-08 13:24:28.791 test2m[2479:207] label: "_$!<Work>!$_"     number: "(604) 456-7891"
2010-03-08 13:24:28.792 test2m[2479:207] label: "_$!<Main>!$_"     number: "(604) 789-1234"
2010-03-08 13:24:28.792 test2m[2479:207] label: "megaphone"     number: "(234) 567-8990"
2010-03-08 13:24:28.793 test2m[2479:207] ---------

What are the markup characters

_$!< and >!$_

surrounding most, save for iPhone, of the default labels for?

Can you point me to where in the "Address Book Programming Guide for iPhone OS" I can find the information?

Thank you for your help.

A: 

I'm running into the same issue. This is what I think so far.

The markup that your seeing indicates to the system that this is a Default label and not a custom label. If you run this code:
NSLog(kABOtherLabel);

you'll ge this result:
_$!<Other>!$_

So that is the value stored in the kABOtherLabel constant (of type CFStringRef). I think the reason iPhone doesn't have the markup around it is becuase it's a 'Custom' label, but it's one originated by Apple instead of the user.

You can give the label any value you like, as evidenced by your megaphone label above. But notice that if you try and create a phone number (or e-mail address) with the label 'other' without using the kABOtherLabel constant or it's value _$!<Other>!$_, the system will think that you're creating a custom label. Like in this example:

ABMultiValueAddValueAndLabel(email, @"[email protected]", @"other", NULL);

And if you go and edit that Address Book entry on the iPhone, it will show up in a separate list of custom labels. (So there will be 2 choices for 'other', one in the defaults and one in the custom labels)

While this hasn't answered your question, I hope it helps.

Andrew
Sorry, I thought I had commented on this before, I probably forgot to hit the button.Thanks for your explanation, I think it's bang on and confirms what I was thinking.
rnistuk