Mapbox RMTileCacheBackgroundDelegate 回调不起作用

Mapbox RMTileCacheBackgroundDelegate callbacks not working

我有下面的 swift 代码。地图上的一切都按预期工作,但我从未看到任何 RMTileCashBackgroundDelegate 方法被调用。我只看到 "Caching started!" 然后什么也没有。我尝试了很多调整,但无法正常工作。任何帮助将不胜感激!

class MapboxViewController: UIViewController, RMMapViewDelegate, RMTileCacheBackgroundDelegate {
    var mapView: RMMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let mapSource:RMMapboxSource = RMMapboxSource(mapID: "myMapId")

        mapView = RMMapView(frame: self.view.bounds, andTilesource: mapSource)
        mapView.delegate = self

        //background caching
        mapView.tileCache.backgroundCacheDelegate = self
        mapView.tileCache.beginBackgroundCacheForTileSource(mapView.tileSource, southWest: swBounds, northEast: neBounds, minZoom: 13, maxZoom: 17)
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        mainView.addSubview(mapView)
    }

    func tileCache(tileCache: RMTileCache!, didBeginBackgroundCacheWithCount tileCount: Int, forTileSource tileSource: RMTileSource) {
        println("Caching started!")
    }
    func tileCache(tileCache: RMTileCache!, didBackgroundCacheTile tile: RMTile, withIndex tileIndex: Int, ofTotalTileCount totalTileCount: Int) {
        println("Cached tile \(tileIndex) of \(totalTileCount)")
    }
    func tileCache(tileCache: RMTileCache!, didReceiveError error: NSError!, whenCachingTile tile: RMTile) {
        println("Error caching tile")
    }
    func tileCacheDidCancelBackgroundCache(tileCache: RMTileCache!) {
        println("Caching cancelled!")
    }
    func tileCacheDidFinishBackgroundCache(tileCache: RMTileCache!) {
        println("Caching complete!")
    }
}

这里有两个问题,一个在上面的代码中并不明显:

  1. tileCache 函数采用 UInt 而不是 Int(在我升级到 Swift 1.2 后强制执行)
  2. 我在 beginBackgroundCacheForTileSource 中的边界框被四舍五入,以至于我最终得到一个没有图块的边界 line。这对我来说很草率,实际上导致了 Mapbox iOS SDK 的崩溃。

感谢Mapbox支持的帮助。这是 Swift 中一个很好的离线缓存示例,供参考:https://github.com/mapbox/mapbox-ios-sdk-offline