ios – “不备份”属性是否适用于“库/缓存”中的数据

Apple的 data storage guidelines声明如下:

2) Data that can be downloaded again or regenerated should be stored
in the /Library/Caches directory.

……(强调我的):

4) 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.

Apple链接到该主题的更多detailed discussion页面没有提及任何有关阻止缓存数据被清除的属性内容.

所以,有人知道“不备份”属性是否实际上对于放置在/ Library / Caches中的项目“不备份和不删除”,或者文件仍然需要存储在应用程序的Documents目录中以确保当设备空间不足时,它们不会被删除

解决方法

我在iPhone 5 iOS 7.1.1上进行了快速测试:

我将一些文件放到“/ Library / Caches”(NSCachesDirectory)并使用NSURLIsExcludedFromBackupKey属性标记它们.然后我以正常方式将更多大文件放到同一目录中.

然后我通过使用相机应用程序拍摄长视频来制作低磁盘空间警告.警告后,标记为“不备份”的文件未从缓存中删除,但其他文件是!所以,这个属性确实起作用,并且尽管它的名称做了两个不同的事情 – 从备份中排除并保留在低空间警告时被清除.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...