Geographic address of person selected in person picker (ABPeoplePickerNavigationController), formatted

StackOverflow https://stackoverflow.com/questions/11399605

Question

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)?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top