是NSURLIsExcludedFromBackupKey递归 [英] Is NSURLIsExcludedFromBackupKey recursive

查看:120
本文介绍了是NSURLIsExcludedFromBackupKey递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文档目录中有一个巨大的文件和目录用于缓存。

I have a huge tree of files and dirs for cache in my document directory.

根据建议,我将使用 NSURLIsExcludedFromBackupKey 用于阻止iTunes使用该应用程序保存此数据。

As recommended, I'm going to use NSURLIsExcludedFromBackupKey for preventing iTunes from saving this data with the app.

我可以在我的根目录网址上使用一次,因为

Can I use it once on my root directory URL, as

[rootDirectoryURL setResourceValue:[NSNumber numberWithBool:YES] forKey:@"NSURLIsExcludedFromBackupKey" error:&error];

或者我必须为每个文件调用它吗?

Or will I have to call it for each file?

推荐答案

是的,您可以将它传递给您想要排除的目录的NSURL。

Yup, you can pass it a NSURL of the directory you want excluded.

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    NSError *error = nil;
    BOOL success = [URL setResourceValue:[NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }

    return success;
}

如果有疑问,你可以测试任何文件

And you can test any files if in doubt using

id flag = nil;
[URL getResourceValue: &flag
               forKey: NSURLIsExcludedFromBackupKey error: &error];
NSLog (@"NSURLIsExcludedFromBackupKey flag value is %@", flag)

这篇关于是NSURLIsExcludedFromBackupKey递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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