How can I clear MKMapView's cache of map tiles?

℡╲_俬逩灬. 提交于 2019-11-29 06:59:58
Felipe Sabino

Try setting NSURLConnection cache size to zero before creating any instance of your MKMapView

    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];

This might make your connections stop storing cached data as the cache remaining size will always be insufficient

I stumbled across this question, and it's certainly an interesting problem. Clearly, the MKMapView is saving the tiles to disk somewhere (because it survives a reboot). I wonder if a potential solution would be to 1) locate where cached tiles are being saved, and then 2) programatically delete that cache when your app starts. This would require a jailbroken device to give you file access outside your application sandbox. Obviously unsuitable for distribution, but for testing would presumably be acceptable.

That said, when I had this problem I ended up just implementing my own tiled map view and running a reachability test to determine whether to display the google map or my offline mode.

We have not found a way to clear the MKMapView Cache from within an App, but you can "Reset All Content and Data" on Settings\General\Reset. While this is not ideal it is much faster than "reflashing the OS" in fact it only takes a few minutes. After the reset you also have set up the device and reload the app, but this also takes another few minutes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!