格式化人员选择器(ABPeoplePickerNavigationController)中选择的人员的地理地址

时间:2012-07-09 16:50:27

标签: ios addressbook abaddressbook abperson

显示ABPeoplePickerNavigationController的人选择器,我可以在字典中获取所选人员的地址:

- (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;
}

根据国家/地区,有关如何格式化此地址的惯例不一样 有没有办法获取选择器显示的地址字符串(类似于Contacts.app显示的内容)?

1 个答案:

答案 0 :(得分:2)

我不确定如何动态创建一组可编辑的地址字段,如在Contacts.app中看到的那样,但是AddressBookUI中有一个实用程序函数,它允许您将地址字典格式化为特定于区域的地址字符串: ABCreateStringWithAddressDictionary。此功能依赖于正确设置的国家/地区代码值;没有说明如果缺少这个值会发生什么。