MKMapView显示用户位置崩溃

我通过app delegate的applicationDidEnterBackground方法在MKMapView对象上设置showsUserLocation = NO。 这是为了阻止它在后台更新用户的位置以节省电池电量。 但是,我似乎收到了这样的少量崩溃日志:

0 MapKit 0x3174c5f6  + 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 

什么是在进入后台之前立即停止用户位置更新而不崩溃的最佳方法? 我搜索了这个问题的解决方案,找不到一个。

您可以尝试的方法是使用以下方法包装呼叫:

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

由于地图似乎认为注释已被删除。 但是,在这种情况下,您仍然不会禁用跟踪。 另一个选择就是不要为iOS 7做这个,因为我认为他已经在8.x解决了。 至少在前者中,即使在大多数情况下剔除了注释,您也可以禁用跟踪。

现在就穿过墙上的东西。

可能的解决方案是执行以下操作:

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