gpt4 book ai didi

ios - 在 iOS 上自动清除(清空/清除)缓存文件夹

转载 作者:技术小花猫 更新时间:2023-10-29 10:37:14 27 4
gpt4 key购买 nike

我有一个应用程序,可让您下载“模块”,以扩展您的应用程序使用范围。
当用户下载模块时,我从服务器获取一个 ZIP 文件并将其解压缩到他的 Caches 文件夹中。 (每个 zip 的大小都可以从 60k 到 2MB 不等)。

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

最近,我收到很多关于模块从用户设备上消失的投诉,所以我做了一些调查,并在 Apple 的文档中发现了以下措辞。

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

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

所以我有几个问题:

  1. 你们中有人遇到过类似的情况吗?如果遇到过,怎么办?
  2. 有谁知道 iOS 何时清除缓存?什么被认为是“低空间”警告?这样我至少可以警告用户他没有足够的空间来安装新模块。
  3. 有没有办法在清除缓存文件夹之前收到某种警告?

这是 Apple 的一个非常令人沮丧的举动,我真的看不到出路。真的很想听听您的一些想法。

最佳答案

编辑:经过一些测试,这似乎工作得很好并且没有被清除。

这还没有 100% 得到证实,但它在我们的基本测试中运行良好(我会在它们出现时发布更全面的结果)。将数据保存到应用程序的“应用程序支持”文件夹似乎可以解决这些问题,因为该文件夹未被清除。

docs状态:

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.`

您可以按如下方式进入该文件夹(请注意按照苹果官方文档的要求附加包 ID):

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

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

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

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

关于ios - 在 iOS 上自动清除(清空/清除)缓存文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11452145/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com