2013-09-23 80 views
6

我的申請於iOS6的工作正常,但它墜毀在iOS 7,由於惡劣的訪問時,我添加疊加MKMapView.My代碼如下添加MKPolyline覆蓋到的MKMapView崩潰的應用程序

MKPolyline *polyline = [[MKPolyline alloc] init]; 
    polyline = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps]; 
    [directionMap addOverlay:polyline]; 

enter image description here

這是崩潰日誌 (LLDB)BT *

thread #51: tid = 0x1cc5, 0x38755f8c libdispatch.dylib`dispatch_retain$VARIANT$mp + 8, stop reason = EXC_BAD_ACCESS (code=1, address=0x0) 
    frame #0: 0x38755f8c libdispatch.dylib`dispatch_retain$VARIANT$mp + 8 
    frame #1: 0x3598dbc8 VectorKit`-[VKRasterOverlayTileSource init] + 176 
    frame #2: 0x358cfd24 VectorKit`-[VKMapModel _rasterOverlayTileSourceForLevel:] + 308 
    frame #3: 0x358d0226 VectorKit`-[VKMapModel addRasterOverlay:] + 46 
    frame #4: 0x2f068dfe MapKit`-[MKOverlayContainerView _insertDrawable:forOverlay:atIndex:level:] + 1010 
    frame #5: 0x2f06752e MapKit`-[MKOverlayContainerView _configureAndAddDrawable:forOverlay:level:] + 326 
    frame #6: 0x2f0676ac MapKit`-[MKOverlayContainerView _considerAddingDrawable:inAddRect:level:] + 372 
    frame #7: 0x2f067cce MapKit`-[MKOverlayContainerView addOverlay:level:] + 246 
    frame #8: 0x001394c8 Falcon`-[GetDirectionVC showRouteFrom:to:](self=0x19742820, _cmd=0x001fa466, f=CLLocationCoordinate2D at 0x04f9ec2c, t=CLLocationCoordinate2D at 0x04f9ec1c) + 956 at GetDirectionVC.m:226 
    frame #9: 0x001390ee Falcon`-[GetDirectionVC loadLocations](self=0x19742820, _cmd=0x001fa458) + 1314 at GetDirectionVC.m:173 
    frame #10: 0x2e876e26 Foundation`__NSThread__main__ + 1062 
    frame #11: 0x38891c1c libsystem_pthread.dylib`_pthread_body + 140 
    frame #12: 0x38891b8e libsystem_pthread.dylib`_pthread_start + 102 

(LLDB)

+0

請張貼錯誤日誌。 –

+0

我編輯的問題與崩潰日誌請檢查它。謝謝 –

+0

那麼,在文檔中沒有什麼是MKPolyline的變化,但viewForOverlay方法已被棄用在iOS7.0。嘗試使用 - (MKOverlayRenderer *)rendererForOverlay:(id < MKOverlay >)覆蓋,而不是viewForOverlay方法。 –

回答

18

我有同樣的問題,堆棧跟蹤看起來有誤導性。我的錯誤修正是明確地加在主線程覆蓋:

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

,或者如果你想使用新的MKOverlayRenderer:

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

就我而言,我下載了一些異步數據,生成多義線,創建MKOverlayViews/MKOverlayRenderes(無助於替換棄用的代碼)並將疊加層添加到地圖。

+1

謝謝!正如你所說,我一直在尋找一個解決方案,iOS 7的後臺線程崩潰了。 – Niralp

+0

Splendid!謝謝羅傑 – dijipiji

+0

非常感謝羅傑。 – kalan

1

使用下列如果您在比主線程其他線程建立多晶線:

[self performSelectorOnMainThread:@selector(addPolyLineToMap:) withObject:polyline waitUntilDone:NO]; 

-(void)addPolyLineToMap:(MKPolyline*)apolyline{ 
    [mapview addOverlay:apolyline]; 
}