我读过我可以用 ios 5.1 及更高版本标记具有“不备份”属性的文件夹
据我了解,在这种情况下,目录的所有内容都将从备份中排除。
在我的应用程序中,我们需要从备份中排除 Documents 目录中的所有文件(可以在应用程序执行期间从 Documents 添加或删除这些文件)。我需要将我们的文件存储在 Documents 目录中。
我可以用“不备份属性”标记Documents目录吗?
Apple 允许这样做吗?
这会成为拒绝我们应用的理由吗?
最佳答案
是的,您可以为文档目录的文件夹(文件)设置不备份
标志。
do not backup
属性适用于标记的文件,无论它们位于什么目录,包括 Documents 目录。这些文件不会被清除,也不会包含在用户的 iCloud
备份。由于这些文件确实会占用设备上的存储空间,因此您的应用有责任定期监控和清除这些文件。
for more information for the same go through this link
以下方法设置不备份标志以避免从应用程序目录(文档和缓存)中进行不需要的备份|删除。只需调用以下方法并传递文件夹(文件)的 url。
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
if (&NSURLIsExcludedFromBackupKey == nil) { // for iOS <= 5.0.1
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
} else { // For iOS >= 5.1
NSError *error = nil;
[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
return error == nil;
}
}
关于iphone - 我可以为 iCloud 添加不备份 "Document Directory"吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16316819/