Shmidt Shmidt - 1 year ago 138
iOS Question

How to get formatted address NSString from AddressDictionary?

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]];

Also tried:

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

but this code seems working on Mac OS X only.

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

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

Answer Source

The documentation for the addressDictionary property says:

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.

So add and import the AddressBookUI framework and try:

subtitle = 
    ABCreateStringWithAddressDictionary(placemark.addressDictionary, NO);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download