3
votes

I had read that I can mark folders with "do not backup" attribute.
As I understand, in such case all contents of directory will be excluded from backups.
In our app we need to exclude from backup all files in Documents directory (the files can be added or deleted from Documents during app execution).
We need to store our files in Documents because we use "Application supports iTunes file sharing" feature.
Can we mark Documents directory with "do not backup attribute"?
Does Apple permits this?
Could this become the reason to reject our app?

1

1 Answers

6
votes

According to apple

In iOS 5.0 and earlier, put files in the /Library/Caches directory to prevent them from being backed up

In iOS 5.0.1 and later, put files in the /Library/Application Support directory and apply the com.apple.MobileBackup extended attribute to them. This attribute prevents the files from being backed up to iTunes or iCloud. If you have a large number of support files, you may store them in a custom subdirectory and apply the extended attribute to just the directory.

As far as I know You can not mark documents directory with do not back up attribute

1)you may mark up the individual files inside the documents directory using below code snippet

- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *)filePathString {
        NSURL *fileURL =
        [NSURL fileURLWithPath:filePathString];

        assert([[NSFileManager defaultManager] 
        fileExistsAtPath: [fileURL path]]);

        NSError *error = nil;

        BOOL success = [fileURL setResourceValue:[NSNumber numberWithBool:YES]
                                      forKey:NSURLIsExcludedFromBackupKey
                                     error:&error];
        return success;
    }

2)You may create a subdirectory inside documents folder and apply extended attribute to that.

you may set extended attribute using the below syntax.

int result = setxattr(path, attrName, myDataBytes, [myData length], 0, 0);

you can find more information on reading and writing extended attributes in the following link

I hope this helps