Purva Purva - 3 months ago 10x
iOS Question

Can I add the Do not Back up for the "Document Directory" for iCloud

I had read that I can mark folders with "do not backup" attribute with ios 5.1 and later

As i understand, in such case all contents of directory will be excluded from backups.

In my app we need to exclude from backup all files in Documents directory (the files can be added or deleted from Documents during app execution).I need to store our files in Documents directory.

Can I mark Documents directory with "do not backup attribute"?

Does Apple permits this?

Could this become the reason to reject our app?


Yes you can set the do not backup flag for the folders(file) of Document directory.

do not backup attribute works on marked files regardless of what directory they are in, including the Documents directory.These files will not be purged and will not be included in the user's iCloud backup. Because these files do use on-device storage space, your app is responsible for monitoring and purging these files periodically.

for more information for the same go through this link

Below methods set the Do not back up flag to avoiding the unwanted backup|deletion from the app directory (Document and Cache).just need to call below method and pass url for the Folder(File).

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
    if (&NSURLIsExcludedFromBackupKey == nil) { // for iOS <= 5.0.1
        const char* filePath = [[URL path] fileSystemRepresentation];

        const char* attrName = "com.apple.MobileBackup";
        u_int8_t attrValue = 1;

        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
    } else { // For iOS >= 5.1
        NSError *error = nil;
        [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
        return error == nil;