MKMapView showsUserLocation Crash

℡╲_俬逩灬. 提交于 2019-12-21 12:31:29

问题


I'm setting showsUserLocation = NO on an MKMapView object via the applicationDidEnterBackground method of the app delegate. This is to stop it from updating the user's location whilst in the background to save on battery. However, I seem to be receiving a small number of crash logs like this:

0   MapKit                              0x3174c5f6 <redacted> + 9
1   MapKit                              0x3174c5e9 -[MKQuadTrie contains:] + 24
2   MapKit                              0x3176eaa7 -[MKAnnotationManager _removeAnnotation:updateVisible:removeFromContainer:] + 50
3   MapKit                              0x3176ea6d -[MKAnnotationManager removeAnnotation:] + 28
4   MapKit                              0x31782283 -[MKMapView stopUpdatingUserLocation] + 118

What's the best way of stopping updates for the user's location immediately before going into the background without it crashing? I searched for a solution to this problem and couldn't find one.


回答1:


Something you could try is wrapping the call with:

if (myMapView.userLocationVisible) {
    myMapView.showsUserLocation = NO;
}

Since the map seems to think the annotation has been removed. However you won't be disabling the tracking still in that case. The other option would be to just not do this for iOS 7 since I think t his has been resolved in 8.x. At least in the former you would be able to disable the tracking even when the annotation was culled for you most of the time.

Just through things at a wall at the moment.




回答2:


A possible solution would be to do the following:

if ([annotation isKindOfClass:[MKUserLocation class]]) {
    ((MKUserLocation *)annotation).title = @"My Current Location";
    return nil; //return nil to use default blue dot view
}


来源:https://stackoverflow.com/questions/21672959/mkmapview-showsuserlocation-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!