2

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).

matt
  • 515,959
  • 87
  • 875
  • 1,141
Heider Sati
  • 2,476
  • 26
  • 28
  • I don't understand why you are _creating_ a placemark when you've just been _handed_ the very placemark you need. – matt Oct 27 '17 at 21:32
  • You try my answer, https://stackoverflow.com/questions/47987473/addressdictionary-is-deprecated-first-deprecated-in-ios-11-0-use-propertie – Naresh Sep 21 '18 at 09:21

2 Answers2

2

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
Heider Sati
  • 2,476
  • 26
  • 28
0

You need to access through properties as below

    var placemark = placemarks[0] as? CLPlacemark
    var address = "\(placemark?.thoroughfare ?? ""), \(placemark?.locality ?? ""), \(placemark?.subLocality ?? ""), \(placemark?.administrativeArea ?? ""), \(placemark?.postalCode ?? ""), \(placemark?.country ?? "")"
        print("\(address)")
Sanoj Kashyap
  • 5,020
  • 4
  • 49
  • 75