2010-12-22 63 views
1

我想根據我的地理位置獲取城市名稱。問題是我在這個方法中得到了標題的編譯時錯誤。我做錯了什麼?kABPersonAddressCityKey未聲明的問題

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark 
{ 
    MKPlacemark * myPlacemark = placemark; 
    // with the placemark you can now retrieve the city name 
    NSString *city = [myPlacemark.addressDictionary objectForKey:(NSString*) kABPersonAddressCityKey]; 
} 

回答

11

這個常量來自AddressBook框架,儘管它也在其外部使用。嘗試導入AddressBook標頭以解決您的問題:

#import <AddressBook/AddressBook.h> 
+0

謝謝,就是這樣:) – 1110 2010-12-22 09:55:17

0

由於iOS9您必須使用CNPostalAddressCityKey常量。