MKAnnotationView is not getting displayed in iOS 11
Asked Answered
T

1

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.

Tournai answered 20/9, 2017 at 11:36 Comment(1)
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)?Facelift
F
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!

Facelift answered 20/9, 2017 at 16:30 Comment(13)
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.Blaisdell
Is the callout set with rightCalloutAccessoryView? Mine appears above the view and I'm setting it this way. d.pr/i/5UGGdFFacelift
How is that set Michael, I'm not honestly sure. Would it be like callout.rightCalloutAccessoryView;? Or, callout.rightCalloutAccessoryView = annotation;Blaisdell
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.Blaisdell
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... forums.developer.apple.com/thread/85423Blaisdell
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.Facelift
Thank you Michael, [view prepareForDisplay] (+1) works. As @Blaisdell mentioned I am also observing that callout is going behind the annotations. I tried to call [- bringSubviewToFront: -], but no luck.Tournai
Either of you guys happen to find a solution for the going behind the annotations issue?Blaisdell
Just following up here... anybody have a solution for the going behind issue?Blaisdell
@MichaelRose Did you find anything regarding going annotation behind callout.Tournai
@Jaro Seems to have a solution in these comments (just above).Facelift
@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?Blaisdell
@MichaelRose Did you find anything regarding "going annotation behind callout", I again tried some of other ways around but no luck yet.Tournai

© 2022 - 2024 — McMap. All rights reserved.