Search code examples
iosapp-storebackupicloud

How to understand iOS "Documents and data" (related to cloud backup)


My app was rejected by Apple because they said it doesn't follow the "iOS Data Storage Guidelines."

I have updated the app with the following code to flag downloaded content so that it isn't backed up to the cloud...

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

    NSLog(@"Going to add skip attribute to " @"%@", filePathString);

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

    NSError *error = nil;

    BOOL success = [fileURL setResourceValue:[NSNumber numberWithBool: YES]
                                      forKey: NSURLIsExcludedFromBackupKey
                                       error: &error];
    NSLog(@"Added skip attribute to " @"%@", filePathString);

    return success;
}

However, when I check Settings -> General -> Usage -> MyApp, it displays "Documents and Data" as > 30Mb. This is correct from the point of view that 30Mb of content has been downloaded to the app, but does this also mean that these 30Mb will be backed up to the cloud?

Put in another way, if I flag files so they are not to be backed up, would they be included or excluded from the "Documents and Data" value?

Cheers!


Solution

  • Data that the user created or that is private to the user and that must not just disappear should be in the Documents directory. Also, data which is valuable to the user and that cannot be recreated should be in the Documents directory. Files in the Documents directory are automatically backed up to iCloud.

    Data that is downloaded from the internet should be saved into the Caches directory, because it can easily be redownloaded again, and so it makes no sense to save them to iCloud. The data would just occupy space in the iCloud. If the user needs to restore his device, the app can just redownload the data from wherever it was downloaded from in the first place. The Caches directory can be wiped by the operating system if the amount of free space on the hard disk becomes very low.

    There is a special case, that is files saved in the Documents directory with the NSURLIsExcludedFromBackupKey flag set. This is intended for data which is valuable to the user and that should be available at all time, even when no internet connection is present, but that - on the other hand - can easily be redownloaded or updated whenever needed.

    Contained in the iCloud backup is the contents of the Documents directory excluding the files that have the NSURLIsExcludedFromBackupKey flag set. All other directories that lie inside the app container are not backed up.


    The "Documents and Data" in the settings refer to the size of the Documents folder. The calculation doesn't take into account if anything was excluded from the iCloud backup. The size does not refer to the size of the data in the iCloud backup. However, if the Settings.app says "30MB", you can be sure that the iCloud backup will at least not be greater than 30MB.