2012-07-09 59 views
1

显示一个人选择器与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显示的内容)?

回答

2

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

+0

太棒了,那就是我一直在寻找的东西。我不明白为什么这是在AddressBookUI,可能为什么我忽视它。 – Guillaume 2012-07-09 17:27:10