Disable backup of documents folder and all its sub folders on icloud?

后端 未结 4 993
离开以前
离开以前 2020-12-19 09:55

I have an already running enterprise application which stores a lot of documents inside the documents folders. I wish to disable the iCloud backup of all these documents and

4条回答
  •  生来不讨喜
    2020-12-19 10:42

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *directory = paths[0];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *url = [NSURL fileURLWithPath:directory];
    
    NSError *error;
    // exclude from iCloud backup
    if ([url setResourceValue:@(YES) forKey:NSURLIsExcludedFromBackupKey error:&error] == NO) {
            NSLog(@"Error: Unable to exclude directory from backup: %@", error);
    }
    

    You can call these once at first install. And it will apply on subfolders and files.

提交回复
热议问题