添加“不备份”属性到iOS 5.0.1中的文件夹层次结构 [英] Adding the "Do Not Backup" attribute to a folder hierarchy in iOS 5.0.1

查看:164
本文介绍了添加“不备份”属性到iOS 5.0.1中的文件夹层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone文档文件夹中引用 iCloud +媒体存储,显示如何为文件设置iOS 5.0.1不备份属性。

Referencing iCloud + Storage of media in iPhone Documents folder, which shows how to set the iOS 5.0.1 "Do Not Backup" attribute for a file.

是否有一种有效的方法可以对整个文件夹执行此操作文件层次?例如,我的应用程序创建/ Library / PrivateDocs,并使用多个文件夹,子文件夹和文件填充它。我可以在顶级文件夹中设置do-not-backup属性,还是必须在其下的每个文件和文件夹上设置?

Is there an efficient way to do this for an entire folder/file hierarchy? E.g., my app creates /Library/PrivateDocs, and populates that with several folders, sub-folders, and files. Can I just set the do-not-backup attribute on the top-level folder, or must it be set on every individual file and folder under that also?

而且,如果必须在每个文件/子文件夹上设置,那么这样做的有效方法是什么?

And, if it must be set on each file/subfolder, what's an efficient way to do so?

推荐答案

为了这个目的,您可以在文档目录中放置一个特定目录,将所有内容放入其中,并仅使用

You could put one specific directory inside the documents dir for this purpose, put everything inside and only mark that single directory as do-not-backup using the

 addSkipBackupAttributeToItemAtURL

显示的方法你链接的文章,或使用这个使用路径而不是URL的文章:

method shown in the article you linked, or use this one that uses a path instead of an URL:

+ (void)addSkipBackupAttributeToPath:(NSString*)path {
    u_int8_t b = 1;
    setxattr([path fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}

使用目录的示例:

NSString *docsDirPath = [(AppDelegate*)[[UIApplication sharedApplication] delegate] applicationDocumentsDirectory];
NSString *yourContentsDirPath = [docsDirPath stringByAppendingPathComponent:gContentsDirName];

[Utilities addSkipBackupAttributeToPath:yourContentsDirPath];

我忘记了这个方法在委托中使用以获取文件目录:

I forgot this method use in the delegate to get the documents dir:

- (NSString *)applicationDocumentsDirectory {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}

这篇关于添加“不备份”属性到iOS 5.0.1中的文件夹层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆