在iOS上自动清除(清空/清除)缓存文件夹 [英] Caches folder purged (Emptied/Cleared) automatically on iOS

查看:123
本文介绍了在iOS上自动清除(清空/清除)缓存文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可让您下载可扩展应用程序使用率的模块。

当用户下载模块时,我从服务器获取ZIP文件并将其解压缩到他的Caches文件夹中。 (每个zip文件的大小可在60k到2MB之间。)

I have an app that lets you download "modules" that can expand your app usage.
When the user downloads a module, I fetch a ZIP file from a server and extract it to his Caches folder. (Each of these zips could be sized anywhere from 60k to 2MB).

不幸的是,有超过 300 个模块可用,其中许多用户至少将其中的50-60个下载到他们的设备中。

Unfortunately, there are over 300 modules available, and many of the users download at least 50-60 of these to their device.

最近,我抱怨很多模块只是从用户设备上消失了,因此,我做了一些调查,发现了苹果文档中的以下措辞。

Lately, I got many complaints that modules just disappear off the user device, so I did some investigation and came across the following wording in Apple's documentation.


iOS会在必要时从Caches目录中删除文件,
,因此如果删除了
的数据文件,您的应用将需要适当降级。

iOS will delete your files from the Caches directory when necessary, so your app will need to degrade gracefully if it's data files are deleted.

还有以下文章进一步说明这种情况:
http:/ /iphoneincubator.com/blog/data-management/local-file-storage-in-ios-5

And also the following article explaining further about this situation: http://iphoneincubator.com/blog/data-management/local-file-storage-in-ios-5

我的问题是,我没有实际的方法降级 ,因为我无法自动让用户下载这么多的模块。可能需要几个小时,具体取决于互联网连接和模块的大小。

My problem is, I have no actual way of degrading gracefully, since I can't automatically let the user download so many modules. It could take hours depending on the internet connection and size of the modules.

所以我有几个问题:


  1. 你们有没有人

  2. 有人知道iOS何时清除缓存吗?什么是低空间警告?这样,我至少可以向用户发出警告,告知他空间不足以安装新模块。

  3. 在清除Cache文件夹之前,有没有办法收到某种警告。 ?

这是来自Apple的令人沮丧的举动,我没有真正的出路。真的很想听听您的想法。

This is a really frustrating move from Apple and I don't really see a way out. Would really love to hear some ideas from you.

推荐答案

编辑:经过一些测试,这似乎可以正常工作并且不会被清除。

Edit: After some testing, this seems to work just fine and doesn't get purged.

这还没有100%确认,但是在我们的基本测试中效果很好(我会更详尽地发布结果)。似乎将数据保存到应用程序的应用程序支持文件夹中可以解决这些问题,因为该文件夹未清除。

This isn't 100% confirmed yet, but it worked fine on our basic tests (I'll post more thorough results as they come). It seems saving the data to the app's "Application Support" folder resolves these issues, as this folder isn't purged.

文档状态:


使用应用程序支持目录常量 NSApplicationSupportDirectory ,并附加您的< bundle_ID> 用于:
应用程序为用户创建和管理的资源和数据文件。您可以使用此目录存储应用程序状态信息,计算或下载的数据,甚至存储您代表用户/自动保存文件管理的用户创建的数据。

Use the Application Support directory constant NSApplicationSupportDirectory, appending your <bundle_ID> for: Resource and data files that your app creates and manages for the user. You might use this directory to store app state information, computed or downloaded data, or even user created data that you manage on behalf of the user / Autosave files.`

您可以按以下步骤进入该文件夹(注意,按照Apple官方文档的要求附加捆绑包ID):

You could get to that folder as follows (Notice appending of the bundle ID as requested by the official apple docs):

[[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[[NSBundle mainBundle] bundleIdentifier]]

希望这对任何人都有帮助,正如我所说,我将在周末发布更全面的测试结果。

Hope this helps anyone , and as I said, I will post more thorough test results during the weekend.

编辑2:
添加此行以防止同步来自应用程序支持的临时内容非常重要。我在applicationDidFinishLaunching末尾使用它:

Edit 2: Its very important to add this line to prevent syncing of temporary content from Application Support. I use it in the end of my applicationDidFinishLaunching:

[[NSURL URLWithString:NSApplicationSupportDir] setResourceValue:@(YES) forKey:NSURLIsExcludedFromBackupKey error:nil];

这篇关于在iOS上自动清除(清空/清除)缓存文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆