NSCachesDirectory 中的文件何时被删除?

发布于 2024-11-27 04:59:41 字数 87 浏览 0 评论 0原文

在什么情况下 iOS NSCachesDirectory 中的文件会被删除?显然,删除并重新安装应用程序。应用升级怎么样?磁盘空间不足的情况怎么办?还要别的吗?

In what circumstances would files in the iOS NSCachesDirectory get removed? Obviously, delete and reinstall an application. What about application upgrade? What about low disk space conditions? Anything else?

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

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

发布评论

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

评论(3

忘羡 2024-12-04 04:59:41

我们的经验是,该文件夹会在应用程序更新时被清除。很高兴知道该文件夹何时适合被清除。文档将该文件夹描述为

可丢弃缓存文件的位置(库/缓存)

NSDocumentDirectory 在应用程序更新时不会被清除,但要小心使用此文件夹,因为 iOS 5 现在使用此文件夹在 iCloud 中进行备份,并且您的应用程序可能会如果您使用此目录存储用户生成的内容以外的任何内容,则会被拒绝。

Our experience is that this folder gets cleared on app updates. It would be nice to know when exactly this folder is a candidate for being cleared. The docs describe this folder as

location of discardable cache files (Library/Caches)

The NSDocumentDirectory will not be cleared on app updates but be careful using this folder since iOS 5 now uses this folder for backing up in iCloud and your app will likely be rejected if you use this directory to store anything other then user generated content.

沫雨熙 2024-12-04 04:59:41

在应用程序更新期间,iOS 不会删除 Library 文件夹中的任何内容。

请检查 Apple 的以下文档,其中提到:

当用户下载应用程序更新时,iTunes 会在新的应用程序目录中安装更新。然后,在删除旧安装之前,它将用户的数据文件从旧安装移动到新的应用程序目录。 保证在更新过程中保留以下目录中的文件

Application_Home>/文档

Application_Home>/库

尽管其他用户目录中的文件也可能会被移动,但您不应依赖它们在更新后仍然存在。

这是该文档的链接:
http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/PerformanceTuning/PerformanceTuning.html#//apple_ref/doc/uid/TP40007072-CH8-SW10

希望这有帮助。

Anything which is in Library folder will NOT be deleted by the iOS during App Update.

Please check following documentation from Apple which mentions:

When a user downloads an app update, iTunes installs the update in a new app directory. It then moves the user’s data files from the old installation over to the new app directory before deleting the old installation. Files in the following directories are guaranteed to be preserved during the update process:

Application_Home>/Documents

Application_Home>/Library

Although files in other user directories may also be moved over, you should not rely on them being present after an update.

Here is the link to this documentation:
http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/PerformanceTuning/PerformanceTuning.html#//apple_ref/doc/uid/TP40007072-CH8-SW10

Hope this helps.

溇涏 2024-12-04 04:59:41

内存不足时可以删除 NSCachesDirectory

在 iOS 5.0 及更高版本上,系统可能会删除 Caches 目录
在极少数情况下,系统磁盘空间非常低。这将
应用程序运行时绝不会发生。但是,您应该知道
iTunes 恢复不一定是唯一的条件
Caches目录可以被删除。

更多信息

如果您不希望删除文件,则必须将它们存储在 Documents 目录中,但这方式:

使用“不备份”属性来指定应保留在设备上的文件,即使在存储空间不足的情况下也是如此。将此属性与可以重新创建但即使在存储空间不足的情况下也需要保留的数据一起使用,以便应用程序正常运行,或者因为客户希望它在离线使用期间可用。此属性适用于标记的文件,无论它们位于哪个目录(包括文档目录)。这些文件不会被清除,也不会包含在用户的 iCloud 或 iTunes 备份中。由于这些文件确实使用设备上的存储空间,因此您的应用程序负责定期监视和清除这些文件。

更多信息

NSCachesDirectory can be deleted in cases of low memory

On iOS 5.0 and later, the system may delete the Caches directory on
rare occasions when the system is very low on disk space. This will
never occur while an app is running. However, you should be aware that
iTunes restore is not necessarily the only condition under which the
Caches directory can be erased.

more info

If you don't want your files to be deleted you have to store them in the Documents directory, but this way:

Use the "do not back up" attribute for specifying files that should remain on device, even in low storage situations. Use this attribute with data that can be recreated but needs to persist even in low storage situations for proper functioning of your app or because customers expect it to be available during offline use. This attribute works on marked files regardless of what directory they are in, including the Documents directory. These files will not be purged and will not be included in the user's iCloud or iTunes backup. Because these files do use on-device storage space, your app is responsible for monitoring and purging these files periodically.

more info

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