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

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

문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top