Here's the code I have trying to set up the pin annotation view for the pins on my map. I'm using the default pins already available on MKPinAnnotationView.

#import "ViewController.h"
#import "AKNeutralPin.h" // NSObject <MKAnnotation> class

@interface ViewController () <MKMapViewDelegate>
...

@implementation

...

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[AKNeutralPin class]]) {
         MKPinAnnotationView *neutralPinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"neutral"];
         neutralPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"neutral"];
         neutralPinView.pinColor = MKPinAnnotationColorPurple;
         neutralPinView.canShowCallout = YES;
         return neutralPinView;
}

return nil;
}

The problem is the code works perfectly fine in simulator but not on device. Shows error:

ARC semantic issue no visible @interface for 'MKPinAnnotationView' declares the selector 'initWithAnnotation:reuseIdentifier:.

I've checked the file path of AKNeutralPin.h and .m. They are in the right file path. Not sure what I'm missing here. Any help is much appreciated!

UPDATE: I have exported the code to .ipa file and install on the device. It works well. So I believe the problem doesn't lie in the code but rather some setting changes I made to the built schema unknowing.

1

There are 1 answers

1
Onik IV On

Change to this:

if ([annotation isKindOfClass:[AKNeutralPin class]]) {
     MKPinAnnotationView *neutralPinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"neutral"];
     if(!neutralPinView){
     neutralPinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"neutral"];
    }
     neutralPinView.pinColor = MKPinAnnotationColorPurple;
     neutralPinView.canShowCallout = YES;
     return neutralPinView;
}