Search code examples
xcodemapkitios11reverse-geocodingmkplacemark

addressDictionary is deprecated first deprecated in iOS 11.0


Just started working on IOS11, moving my code from IOS10.3 into IOS11 has resulted in the following challenge, whereas the following code used to work prior to 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];

....

With IOS11 now, it's complaining about PlaceMark.addressDictionary, whereas, addressDictionary is Deprecated.

addressDictionary' is deprecated: first deprecated in iOS 11.0 - Use @properties

I tried to do that, but unfortunately, the InitWithCoordinate function requires AddressDictionary anyway.

I wonder if anyone had the same problem, I know it's very new (IOS11 just came out yesterday).


Solution

  • I think I just found the answer anyway:

    I replaced the following line:

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

    with the following line:

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

    This seems to resolve this problem.