Datasheet
Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
785
Interfacing with the Address Book Application
ABMutableMultiValueRef mutableMultiValueRef =
ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary =
[[NSMutableDictionary alloc] init];
Then, you go on to add the fields you’re interested in to the dictionary:
[addressDictionary setObject:street.text
forKey:(NSString *) kABPersonAddressStreetKey];
[addressDictionary setObject:city.text
forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary setObject:state.text
forKey:(NSString *)kABPersonAddressStateKey];
[addressDictionary setObject:zip.text
forKey:(NSString *)kABPersonAddressZIPKey];
Then you add the value (addressDictionary) and the label (kABWork
Label) to the property (mutableMultiValueRef):
ABMultiValueAddValueAndLabel(mutableMultiValueRef,
addressDictionary, kABWorkLabel, nil);
and set it as the value of the property (kABPersonAddressProperty) in
the personRecord and release the dictionary:
ABRecordSetValue(personRecord, kABPersonAddressProperty,
mutableMultiValueRef,nil);
CFRelease(mutableMultiValueRef);
Then you add the person record to the Address Book you created and then
save it, which actually updates the database:
ABAddressBookAddRecord(addressBook, personRecord, nil);
ABAddressBookSave(addressBook, nil);
Finally, you create the controller, set self as the delegate, give it the person
record to display, and then modally present the controller:
ABNewPersonViewController *picker =
[[ABNewPersonViewController alloc] init];
picker.newPersonViewDelegate = self;
picker.displayedPerson = personRecord;
UINavigationController* navigationController =
[[UINavigationController alloc]
initWithRootViewController:picker];
self presentModalViewController:navigationController
animated:YES];
[picker release];
41_542934-bk07ch01.indd 78541_542934-bk07ch01.indd 785 3/23/10 11:01 PM3/23/10 11:01 PM