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?
在什么情况下iOS NSCachesDirectory中的文件会被删除?显然,删除并重新安装应用程序。应用程序升级呢?那么低磁盘空间的情况呢?还有别的事吗?
3 个解决方案
#1
10
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.
NSDocumentDirectory不会在应用程序更新时被清除,但使用此文件夹时要小心,因为iOS 5现在使用此文件夹在iCloud中进行备份,如果您使用此目录存储除用户生成内容之外的任何内容,您的应用程序可能会被拒绝。
#2
9
Anything which is in Library folder will NOT be deleted by the iOS during App Update.
在App更新过程中,库文件夹中的任何内容都不会被iOS删除。
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:
当用户下载应用程序更新时,iTunes会在新的应用目录中安装更新。然后,它将用户的数据文件从旧安装移动到新应用程序目录,然后删除旧安装。以下目录中的文件保证在更新过程中保存:
Application_Home>/Documents
Application_Home > /文件
Application_Home>/Library
Application_Home > /库
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
这里是这个文档的链接:http://developer.apple.com/library/ios/#文档/iPhone/概念性/iPhoneOSProgrammingGuide/PerformanceTuning .html#/ apple_ref/doc/uid/TP40007072-CH8-SW10
Hope this helps.
希望这个有帮助。
#3
0
NSCachesDirectory can be deleted in cases of low memory
在内存不足的情况下,可以删除NSCachesDirectory
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.
在iOS 5.0或更高版本中,系统在磁盘空间非常低的情况下,偶尔会删除缓存目录。当应用程序运行时,这种情况永远不会发生。但是,您应该知道,iTunes恢复不一定是删除目录的唯一条件。
更多信息
If you don't want your files to be deleted you have to store them in the Documents directory, but this way:
如果您不希望删除您的文件,您必须将它们存储在Documents目录中,但是这样做:
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.
使用“不要备份”属性指定应该保留在设备上的文件,即使是在低存储情况下。使用这个属性,数据可以被重新创建,但是需要在低存储情况下保存,以保证应用程序的正常运行,或者因为客户希望它在离线使用时可用。此属性可用于标记的文件,而不管它们位于哪个目录(包括Documents目录)。这些文件不会被清除,也不会包含在用户的iCloud或iTunes备份中。因为这些文件确实使用设备存储空间,所以您的应用程序负责定期监视和清除这些文件。
更多信息
#1
10
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.
NSDocumentDirectory不会在应用程序更新时被清除,但使用此文件夹时要小心,因为iOS 5现在使用此文件夹在iCloud中进行备份,如果您使用此目录存储除用户生成内容之外的任何内容,您的应用程序可能会被拒绝。
#2
9
Anything which is in Library folder will NOT be deleted by the iOS during App Update.
在App更新过程中,库文件夹中的任何内容都不会被iOS删除。
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:
当用户下载应用程序更新时,iTunes会在新的应用目录中安装更新。然后,它将用户的数据文件从旧安装移动到新应用程序目录,然后删除旧安装。以下目录中的文件保证在更新过程中保存:
Application_Home>/Documents
Application_Home > /文件
Application_Home>/Library
Application_Home > /库
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
这里是这个文档的链接:http://developer.apple.com/library/ios/#文档/iPhone/概念性/iPhoneOSProgrammingGuide/PerformanceTuning .html#/ apple_ref/doc/uid/TP40007072-CH8-SW10
Hope this helps.
希望这个有帮助。
#3
0
NSCachesDirectory can be deleted in cases of low memory
在内存不足的情况下,可以删除NSCachesDirectory
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.
在iOS 5.0或更高版本中,系统在磁盘空间非常低的情况下,偶尔会删除缓存目录。当应用程序运行时,这种情况永远不会发生。但是,您应该知道,iTunes恢复不一定是删除目录的唯一条件。
更多信息
If you don't want your files to be deleted you have to store them in the Documents directory, but this way:
如果您不希望删除您的文件,您必须将它们存储在Documents目录中,但是这样做:
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.
使用“不要备份”属性指定应该保留在设备上的文件,即使是在低存储情况下。使用这个属性,数据可以被重新创建,但是需要在低存储情况下保存,以保证应用程序的正常运行,或者因为客户希望它在离线使用时可用。此属性可用于标记的文件,而不管它们位于哪个目录(包括Documents目录)。这些文件不会被清除,也不会包含在用户的iCloud或iTunes备份中。因为这些文件确实使用设备存储空间,所以您的应用程序负责定期监视和清除这些文件。
更多信息