Disable backing up the document folder and all its subfolders on icloud?

I have an already running corporate application that stores a lot of documents inside document folders. I want to disable iCloud backup of all these documents and folders inside the Documents folder. The problem is that the contents inside the folder continue to change dynamically, and the idea of ​​adding kCFURLIsExcludedFromBackupKeyfor each file sounds a bit complicated, since there are several classes in my code that can be written to the document directory.

Can I disable the download of the entire document folder and its subfolder.

+4
source share
4 answers

, , ? , <Application_Home>/Documents <Application_Home>/Library/Caches. . , , , , .

. Apple : https://developer.apple.com/icloud/documentation/data-storage/index.html

+4

appDelegate

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

    NSArray *urlArray = [[NSFileManager defaultManager] URLsForDirectory: NSDocumentDirectory inDomains: NSUserDomainMask];
    NSURL *documentsUrl = [urlArray firstObject];

    NSError *error = nil;
    BOOL success = [documentsUrl setResourceValue: [NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error in disabling %@ from backup %@", [documentsUrl lastPathComponent], error);
    }
+4
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);
}

. .

+3

kCFURLIsExcludedFromBackupKey ( NSURLIsExcludedFromBackupKey) , . , , - , , . "" . , , , Caches, . , tmp/.

Apple , .

+2

All Articles