Datasheet

Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
779
Interfacing with the Address Book Application
NSString *firstName = (NSString*)
ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (NSString*)
ABRecordCopyValue(person, kABPersonLastNameProperty);
if (!(name.text)) name.text = [[NSString alloc]
initWithFormat: @”%@ %@”, firstName, lastName ];
As you might expect, other properties that a person can have more than one
of, such as street address and phone number, are multi-value properties.
Multi-value properties consist of a list of values. Each value has a text label
and an identifier associated with it. There can be more than one value with
the same label, but the identifier is always unique.
These properties are ABMutableMultiValueRefs. And just to make your
life interesting, there are two types of ABMutableMultiValueRefs you’ll
have to contend with;
kABMultiStringPropertyType, which, as you might expect, are
strings.
kABMultiDictionaryPropertyType, which, as you might expect, are
dictionaries.
Although you won’t be using the phone number in RoadTrip, this part of
Listing 1-20 is how you would access it:
ABMultiValueRef multiValueRef = (NSString*)
ABRecordCopyValue(person,kABPersonPhoneProperty);
NSString *phoneLabel;
NSString *iPhone=@””;
NSString *homePhone=@””;
for(int i=0 ;i < ABMultiValueGetCount(multiValueRef);
i++) {
phoneLabel=(NSString*)
ABMultiValueCopyLabelAtIndex(multiValueRef,i);
if([phoneLabel isEqualToString:
(NSString*)kABPersonPhoneIPhoneLabel])
iPhone = (NSString*)
ABMultiValueCopyValueAtIndex(multiValueRef,i);
if([phoneLabel isEqualToString:(NSString*)kABHomeLabel])
homePhone = (NSString*)
ABMultiValueCopyValueAtIndex(multiValueRef,i);
}
Here, a person has multiple phone numbers, each of which has a text label.
(In this example, I just look for iPhone and home, but you get the picture.)
Walking through this section of Listing 1-20, you see that the first thing you
do is get the property using the ABRecordCopyValue function.
41_542934-bk07ch01.indd 77941_542934-bk07ch01.indd 779 3/23/10 11:01 PM3/23/10 11:01 PM