5

I am having an application running on app store, which has map view with other functionality.

Everything works perfectly till iOS 10 (all versions except iOS 11), now when I tested same app on iOS 11, then MKAnnotationView is not getting displayed (This happens only with iOS 11).

There is no any exception/error shown. I went thought apple documentation, but there is no any such deprecation in API's, but still its not working.

Can someone please help me out in this issue.

Daniel
  • 8,794
  • 4
  • 48
  • 71
iLearner
  • 1,670
  • 2
  • 19
  • 45
  • Having the same issue. Currently looking into the fix. Also, have you noticed the map view in the Xcode 9 Simulator is unusable (100% CPU)? – rosem Sep 20 '17 at 14:17

1 Answers1

10

I was able to get it to display by calling "prepareForDisplay" on the annotation view within the viewForAnnotation delegate method. prepareForDisplay is a new method in iOS 11, but it is not documented.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

    // Current Location Annotation
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        return nil;
    }

    // Custom Annotation
    if ([annotation isKindOfClass:[CustomAnnotationView class]]) {
        CustomAnnotationView *view = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Custom"];
        if (!view) {
            view = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Custom"];
        } else {
            view.annotation = annotation;
        }

        if (@available(iOS 11.0, *)) {
            [view prepareForDisplay];
        }

        return view;
    }

    return nil;
}

I'm still trying to figure out if this is a bug or proper use. Stay tuned!

rosem
  • 1,311
  • 14
  • 19
  • 3
    Michael, that did cause it to display. Thanks for mentioning that needle in the haystack, whew. However, even with this. The callout seems to go behind the annotations. Any thought on that? And yes, maps being slow. It is pretty much unusable, crazy. It is soooooo slow in the simulator. – d3020 Sep 20 '17 at 17:13
  • Is the callout set with rightCalloutAccessoryView? Mine appears above the view and I'm setting it this way. http://d.pr/i/5UGGdF – rosem Sep 20 '17 at 17:41
  • How is that set Michael, I'm not honestly sure. Would it be like callout.rightCalloutAccessoryView;? Or, callout.rightCalloutAccessoryView = annotation; – d3020 Sep 20 '17 at 17:52
  • Michael, I would be curious if you experience this too though when you have more annotations on the map. Where it might be a little more obvious if the callout was going behind them. As it is now, in your example, you really couldn't tell if it was because that other annotation is to far away. Thanks for your help here... Would like to get this sorted asap. – d3020 Sep 20 '17 at 18:11
  • Michael, just in case it helps you to help me here. I wanted to mention, the callouts I have appear fine in os versions prior to 11. In other words, their not going behind the annotations. Just wanted to clarify that is all. Thanks. For what it's also worth to mention. Looks like I'm not the only one dealing with this going behind issue, but still with no resolve... https://forums.developer.apple.com/thread/85423 – d3020 Sep 20 '17 at 20:28
  • I do grouping on my annotations if they touch, so I can't confirm. Obviously, a lot has changed in MapKit with iOS 11. It might be worth the time to watch the "What's new in MapKit" WWDC 2017 video and refactor your code. I'm assuming all these weird bugs are because of all the changes they've made and there is a new/better way to implement. – rosem Sep 21 '17 at 00:25
  • Thank you Michael, [view prepareForDisplay] (+1) works. As @d3020 mentioned I am also observing that callout is going behind the annotations. I tried to call [- bringSubviewToFront: -], but no luck. – iLearner Sep 21 '17 at 06:04
  • Either of you guys happen to find a solution for the going behind the annotations issue? – d3020 Sep 22 '17 at 12:33
  • Just following up here... anybody have a solution for the going behind issue? – d3020 Oct 05 '17 at 20:07
  • @MichaelRose Did you find anything regarding going annotation behind callout. – iLearner Oct 09 '17 at 09:50
  • @Jaro Seems to have a solution in these comments (just above). – rosem Oct 09 '17 at 12:58
  • @Jaro I've tried both solutions and neither one seems to make any difference. :( I have about 100 or so annotations on my map. When I tap on any of them. The callout still will go behind them when using what you suggested. Doesn't seem to make any difference at all. Do I need to put the solution 1 code maybe in the did select annotation function maybe? – d3020 Oct 09 '17 at 17:12
  • @MichaelRose Did you find anything regarding "going annotation behind callout", I again tried some of other ways around but no luck yet. – iLearner Nov 27 '17 at 06:28