Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKAnnotationView is not getting displayed in iOS 11

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.

like image 706
iLearner Avatar asked Sep 20 '17 11:09

iLearner


1 Answers

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!

like image 108
Michael Rose Avatar answered Nov 08 '22 22:11

Michael Rose