Datasheet
Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
777
Interfacing with the Address Book Application
Listing 1-20: peoplePickerNavigationController:
shouldContinueAfterSelectingPerson:
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
name.text = (NSString*) ABRecordCopyValue(person,
kABPersonOrganizationProperty);
NSString *firstName = (NSString*)
ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (NSString*)
ABRecordCopyValue(person, kABPersonLastNameProperty);
if (!name.text) name.text = [[NSString alloc]
initWithFormat: @”%@ %@”, firstName, lastName ];
ABMultiValueRef multiValueRef = (NSString*)
ABRecordCopyValue(person,kABPersonPhoneProperty);
NSString* phoneLabel;
NSString* iPhone=@””;
NSString* homePhone=@””;
for (int i=0;i <
ABMultiValueGetCount(multiValueRef);i++) {
phoneLabel = (NSString*) ABMultiValueCopyLabelAtIndex(mul
tiValueRef, i);
if([phoneLabel isEqualToString:
(NSString*)kABPersonPhoneIPhoneLabel])
iPhone = (NSString*) ABMultiValueCopyValueAtIndex(multi
ValueRef,i);
if([phoneLabel isEqualToString:(NSString*)kABHomeLabel])
homePhone = (NSString*) ABMultiValueCopyValueAtIndex(mu
ltiValueRef,i);
}
multiValueRef = ABRecordCopyValue
(person, kABPersonAddressProperty);
if (ABMultiValueGetCount(multiValueRef) > 0) {
CFDictionaryRef dictionary = ABMultiValueCopyValueAtIndex
(multiValueRef, 0);
street.text = (NSString*) CFDictionaryGetValue
(dictionary,
kABPersonAddressStreetKey);
city.text = (NSString*)CFDictionaryGetValue
(dictionary, kABPersonAddressCityKey);
state.text = (NSString*)CFDictionaryGetValue
(dictionary, kABPersonAddressStateKey);
zip.text = (NSString*)CFDictionaryGetValue
dictionary, kABPersonAddressZIPKey);
CFRelease(dictionary);
}
CFRelease(multiValueRef);
[self dismissModalViewControllerAnimated:YES];
return NO;
}
41_542934-bk07ch01.indd 77741_542934-bk07ch01.indd 777 3/23/10 11:01 PM3/23/10 11:01 PM