我有下面的快捷代码。地图上的所有内容都按预期工作,但我从未看到任何RMTileCashBackgroundDelegate方法被调用。我所看到的只是"缓存开始了!"然后什么也没有。我已经尝试了很多调整,但无法实现这一目标。任何帮助将不胜感激!
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!")
}
}
答案 0 :(得分:0)
这里有两个问题,一个在上面的代码中并不明显:
感谢Mapbox对他们的帮助。这是Swift中一个不错的离线缓存示例供参考:https://github.com/mapbox/mapbox-ios-sdk-offline