NSCachesDirectory 中的文件何时被删除?
在什么情况下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们的经验是,该文件夹会在应用程序更新时被清除。很高兴知道该文件夹何时适合被清除。文档将该文件夹描述为
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
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.在应用程序更新期间,iOS 不会删除 Library 文件夹中的任何内容。
请检查 Apple 的以下文档,其中提到:
这是该文档的链接:
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:
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.
内存不足时可以删除 NSCachesDirectory
更多信息
如果您不希望删除文件,则必须将它们存储在 Documents 目录中,但这方式:
使用“不备份”属性来指定应保留在设备上的文件,即使在存储空间不足的情况下也是如此。将此属性与可以重新创建但即使在存储空间不足的情况下也需要保留的数据一起使用,以便应用程序正常运行,或者因为客户希望它在离线使用期间可用。此属性适用于标记的文件,无论它们位于哪个目录(包括文档目录)。这些文件不会被清除,也不会包含在用户的 iCloud 或 iTunes 备份中。由于这些文件确实使用设备上的存储空间,因此您的应用程序负责定期监视和清除这些文件。
更多信息
NSCachesDirectory can be deleted in cases of low memory
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