仅在iOS 9上崩溃:[MKPlacemark initWithCoordinate:]:无法识别的选择器

时间:2017-01-05 13:29:15

标签: ios objective-c crash unrecognized-selector mkplacemark

代码:

-(void)getRouteDirections{
    MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
    [request setSource:[MKMapItem mapItemForCurrentLocation]];

    // It crashes on this line:      
    MKPlacemark * placemark = [[MKPlacemark alloc]initWithCoordinate:_location.coordinate];
}

例外:

  

- [MKPlacemark initWithCoordinate:]:发送到实例的无法识别的选择器

它仅在iOS 9上崩溃。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

来自Larme评论的回答:

自iOS10起,

- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coordinate;可用。

对于iOS 9或更早版本,自{3}以来initWithCoordinate:addressDictionary:可用。