【问题标题】:addressDictionary is deprecated first deprecated in iOS 11.0addressDictionary 在 iOS 11.0 中首先被弃用
【发布时间】:2018-03-04 13:05:22
【问题描述】:

刚开始在 IOS11 上工作,将我的代码从 IOS10.3 移到 IOS11 导致了以下挑战,而以下代码曾经在 IOS11 之前工作:

    CLGeocoder *GeoCoder = [[CLGeocoder alloc] init];
[GeoCoder reverseGeocodeLocation:_LocationManager.location completionHandler:^(NSArray *PlaceMarks, NSError *Error)
 {
     if (!Error)
     {
         MKPlacemark *PlaceMark_MK;

         if (PlaceMarks.count > 0)
         {
             MKPlacemark *PlaceMark = [PlaceMarks objectAtIndex:0];

             if (PlaceMark.location.coordinate.latitude != 0.0F && PlaceMark.location.coordinate.longitude != 0.0F)
             {
                 PlaceMark_MK = [[MKPlacemark alloc] initWithCoordinate:PlaceMark.location.coordinate addressDictionary:PlaceMark.addressDictionary];

....

现在使用 IOS11,它抱怨 PlaceMark.addressDictionary,而 addressDictionary 已弃用。

addressDictionary' 已弃用:首先在 iOS 11.0 中弃用 - 使用 @properties

我尝试这样做,但不幸的是,InitWithCoordinate 函数无论如何都需要 AddressDictionary。

不知道有没有人有同样的问题,我知道它很新(IOS11 昨天刚出)。

【问题讨论】:

标签: xcode mapkit ios11 reverse-geocoding mkplacemark


【解决方案1】:

我想我还是找到了答案:

我替换了以下行:

PlaceMark_MK = [[MKPlacemark alloc] initWithCoordinate:PlaceMark.location.coordinate addressDictionary:PlaceMark.addressDictionary];

下面一行:

PlaceMark_MK = [[MKPlacemark alloc] initWithCoordinate:PlaceMark.location.coordinate postalAddress:PlaceMark.postalAddress];

这似乎解决了这个问题。

【讨论】:

  • 谢谢 :-) 还 import Contacts (希望它有助于节省其他人的时间)
【解决方案2】:

您需要通过以下属性访问

    var placemark = placemarks[0] as? CLPlacemark
    var address = "\(placemark?.thoroughfare ?? ""), \(placemark?.locality ?? ""), \(placemark?.subLocality ?? ""), \(placemark?.administrativeArea ?? ""), \(placemark?.postalCode ?? ""), \(placemark?.country ?? "")"
        print("\(address)")

【讨论】:

    猜你喜欢
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 2017-11-07
    相关资源
    最近更新 更多