如何清除 MKMapView 的地图图块缓存?

发布于 2024-10-06 10:25:19 字数 492 浏览 3 评论 0原文

我正在开发一个基于 MKMapView 的 iPhone / iPad 地图应用程序,该应用程序覆盖我自己的基本底图,以提供一些有限的功能,即使用户处于离线状态且无法访问 Google 的地图图块服务器时也是如此。

此功能正在运行 - 但我在每次新构建后都很难对其进行测试,因为我找不到刷新/重置 iOS 地图图块缓存的方法。 iOS 缓存甚至可以在 iOS 设备重启和重新启动后继续存在。我使用之前测试会话中内存中的图块放大了过去渲染的任何地方。

有没有办法强制 iOS 刷新其地图缓存?现在我能想到的唯一选择是每次需要进行测试时重新刷新操作系统。

谢谢!

顺便说一句:这几乎是这个问题的重复,但在这种情况下问题是不是用空缓存进行测试,而是释放内存。那里给出的已接受答案集中在 RAM 问题上,而不是我在这里遇到的相同问题。

I am working on an MKMapView based iPhone / iPad mapping app that overlays my own basic base map to provide for some limited functionality even when users are offline and can not reach Google's map tile server.

This functionality is working - but I am having a hard time testing it after each new build because I can't find a way to flush / reset the iOS map tile cache. The iOS cache even survives a power-cycle and reboot of the iOS device. Anywhere I have zoomed into in the past renders with the tiles in memory from the prior test session.

Is there a way to force iOS to flush its map cache? Right now the only alternative I can think of is to reflash the OS every time I need to do a test.

Thanks!

BTW: This is almost a duplicate of this question, but in that case the issue wasn't testing with an empty cache, but rather freeing up memory. The accepted answer given there focused on the RAM issue, not the same problem that I am having here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

弃爱 2024-10-13 10:25:19

在创建 MKMapView 的任何实例之前,尝试将 NSURLConnection 缓存大小设置为零,

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

这可能会使您的连接停止存储缓存数据,因为缓存剩余大小始终不足

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

吐个泡泡 2024-10-13 10:25:19

我偶然发现了这个问题,这确实是一个有趣的问题。显然,MKMapView 正在将图块保存到磁盘上的某个位置(因为它在重新启动后仍然存在)。我想知道潜在的解决方案是否是 1)找到保存缓存图块的位置,然后 2)在应用程序启动时以编程方式删除该缓存。这需要越狱设备才能让您在应用程序沙箱之外访问文件。显然不适合分发,但用于测试大概是可以接受的。

也就是说,当我遇到这个问题时,我最终只是实现了自己的平铺地图视图并运行可达性测试来确定是显示谷歌地图还是我的离线模式。

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.

梦冥 2024-10-13 10:25:19

我们尚未找到从应用程序内清除 MKMapView 缓存的方法,但您可以在“设置\常规\重置”中“重置所有内容和数据”。
虽然这并不理想,但它比“刷新操作系统”要快得多,实际上只需要几分钟。
重置后,您还设置了设备并重新加载应用程序,但这还需要几分钟。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文