如何从AddressDictionary获取格式化地址NSString?

问题描述:

尝试从AddressDictionary获取格式化地址,这是我从CLGeocoder获得的。
使用以下代码但没有结果:

Trying to get formatted address from AddressDictionary, that I got from CLGeocoder. Used following code with no result:

subtitle = [NSString stringWithString:[[addressDict objectForKey:@"FormattedAddressLines"]objectAtIndex:0]];

还试过:

subtitle = [[[ABAddressBook sharedAddressBook] formattedAddressFromDictionary:placemark.addressDictionary] string];

但此代码似乎仅适用于Mac OS X.

but this code seems working on Mac OS X only.

编译器询问ABAdressBook,但我导入了两个头文件。

Compiler asks about ABAdressBook, but I have both header files imported.

#import <AddressBook/ABAddressBook.h>
#import <AddressBook/AddressBook.h>


地址字典的文档属性说:


您可以格式化此词典的内容以获取完整地址
string而不是自己建立地址。要格式化
字典,请使用ABCreateStringWithAddressDictionary函数作为地址簿UI函数参考中描述的

You can format the contents of this dictionary to get a full address string as opposed to building the address yourself. To format the dictionary, use the ABCreateStringWithAddressDictionary function as described in Address Book UI Functions Reference.

所以添加并导入 AddressBookUI 框架并尝试:

So add and import the AddressBookUI framework and try:

subtitle = 
    ABCreateStringWithAddressDictionary(placemark.addressDictionary, NO);