标记目录以避免iCloud备份

时间:2014-12-01 20:50:32

标签: ios icloud

我的应用程序的最新更新最近被拒绝,因为单个目录太大而无法备份(36MB)。这个目录(/Documents/Templates/)不需要备份到iCloud,所以我很好奇如何在备份发生时标记要避免的目录。

这是我目前被拒绝的内容: 的 AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [self addSkipBackupAttributeToItemAtURL:finalURL];

    return YES;
}

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL

{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
    NSString *directory = [paths objectAtIndex:0];
    directory = [directory stringByAppendingPathComponent:@"Templates"];

    NSFileManager *fileManager = [NSFileManager defaultManager];

    if ([fileManager fileExistsAtPath:directory] == NO) {

        NSError *error;
        if ([fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&error] == NO) {
            NSLog(@"Error: Unable to create directory: %@", error);
        }

        NSURL *url = [NSURL fileURLWithPath:directory];
        // exclude downloads from iCloud backup
        if ([url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error] == NO) {
            NSLog(@"Error: Unable to exclude directory from backup: %@", error);
        }
    }
}

如果有人能帮助我,那就太棒了,谢谢。

0 个答案:

没有答案