我可以为“文档目录”添加“不备份”吗?对于iCloud [英] Can I add the Do not Back up for the "Document Directory" for iCloud
问题描述
我读过我可以使用ios 5.1及更高版本标记不备份属性的文件夹
I had read that I can mark folders with "do not backup" attribute with ios 5.1 and later
据我所知,在这种情况下,目录的所有内容都将从备份中排除。
As i understand, in such case all contents of directory will be excluded from backups.
在我的应用程序中,我们需要从备份中排除Documents目录中的所有文件(可以在应用程序执行期间从文档中添加或删除文件).I需要将我们的文件存储在Documents目录中。
In my app we need to exclude from backup all files in Documents directory (the files can be added or deleted from Documents during app execution).I need to store our files in Documents directory.
我可以使用不备份属性标记文档目录吗?
Can I mark Documents directory with "do not backup attribute"?
Apple是否允许这样做?
Does Apple permits this?
这可能成为拒绝我们应用程序的理由吗?
Could this become the reason to reject our app?
推荐答案
是的,你可以为文件目录的文件夹(文件)设置不备份
标志。
Yes you can set the do not backup
flag for the folders(file) of Document directory.
不备份
属性对标记文件有效,无论它们在哪个目录中,包括Documents目录。这些文件不会被清除,也不会包含在用户的 iCloud
返回向上。由于这些文件确实使用设备上的存储空间,因此您的应用程序负责定期监视和清除这些文件。
do not backup
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
backup. Because these files do use on-device storage space, your app is responsible for monitoring and purging these files periodically.
下面的方法设置了不备份标志,以避免从应用程序目录(文档和缓存)中删除不需要的备份。必须调用以下方法并传递文件夹的URL(文件)。
Below methods set the Do not back up flag to avoiding the unwanted backup|deletion from the app directory (Document and Cache).just need to call below method and pass url for the Folder(File).
- (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;
}
}
这篇关于我可以为“文档目录”添加“不备份”吗?对于iCloud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!