Showing a person picker with ABPeoplePickerNavigationController
, I can get the address of the selected person in a dictionary with this:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
if (property == kABPersonAddressProperty) {
ABMultiValueRef addressMultiValue = ABRecordCopyValue(person, kABPersonAddressProperty);
NSDictionary *address = (NSDictionary *)CFBridgingRelease(ABMultiValueCopyValueAtIndex(addressMultiValue, ABMultiValueGetIndexForIdentifier(addressMultiValue, identifier)));
}
[self dismissModalViewControllerAnimated:YES];
return NO;
}
Depending on the country, the convention on how to format this address is not the same.
Is there a way to get the string of the address as displayed by the picker (similar to what Contacts.app shows)?
I'm not sure how to dynamically create a set of editable address fields as you see in Contacts.app, but there is a utility function in AddressBookUI that allows you to format an address dictionary into a region-specific address string: ABCreateStringWithAddressDictionary
. This function relies on the country code value being set correctly; it's unspecified what happens if this value is missing.