我读过我可以用“不备份”属性标记文件夹。
据我了解,在这种情况下,目录的所有内容都将从备份中排除。
在我们的应用程序中,我们需要从备份中排除文档目录中的所有文件(可以在应用程序执行期间从文档中添加或删除这些文件)。
我们需要将文件存储在 Documents 中,因为我们使用“应用程序支持 iTunes 文件共享”功能。
能否给Documents目录加上“不备份属性”?
Apple 允许这样做吗?
这会成为拒绝我们应用程序的理由吗?
最佳答案
据苹果称
In iOS 5.0 and earlier, put files in the /Library/Caches directory to prevent them from being backed up
In iOS 5.0.1 and later, put files in the /Library/Application Support directory and apply the com.apple.MobileBackup extended attribute to them. This attribute prevents the files from being backed up to iTunes or iCloud. If you have a large number of support files, you may store them in a custom subdirectory and apply the extended attribute to just the directory.
据我所知 您不能使用不备份属性标记文档目录
1)您可以使用以下代码片段标记文档目录中的各个文件
- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *)filePathString {
NSURL *fileURL =
[NSURL fileURLWithPath:filePathString];
assert([[NSFileManager defaultManager]
fileExistsAtPath: [fileURL path]]);
NSError *error = nil;
BOOL success = [fileURL setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:&error];
return success;
}
2)您可以在文档文件夹中创建一个子目录,并对其应用扩展属性。
您可以使用以下语法设置扩展属性。
int result = setxattr(path, attrName, myDataBytes, [myData length], 0, 0);
您可以在以下link 中找到有关读写扩展属性的更多信息
希望对你有帮助
关于ios - 我可以用 "do not backup"属性标记文档目录吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16009693/