Adding MKPolyline Overlay to MKMapView crashes application

前端 未结 2 1449
臣服心动
臣服心动 2020-12-31 23:43

My application was working fine on iOS6 but it is crashing on iOS 7 due to bad access when I add overlay to MKMapView.My code is as follows

MKPolyline *polyl         


        
2条回答
  •  清歌不尽
    2021-01-01 00:17

    I had the same problem, the stack trace looks misleading to me. My bugfix is to explicitely add the overlay on the main thread:

    dispatch_async(dispatch_get_main_queue(), ^{
      [mapView addOverlay:myRouteLine];
    });
    

    or if you'd like to use the new MKOverlayRenderer:

    dispatch_async(dispatch_get_main_queue(), ^{
      [mapView addOverlay:myRouteLine level:MKOverlayLevelAboveRoads];
    });
    

    In my case, I'm downloading asynchronously some data, generate Polylines, create MKOverlayViews / MKOverlayRenderes (didn't help to replace the deprecated code) and add the overlay to the map.

提交回复
热议问题