Question

What is the recommended place to save game data if I do not want automatically to be backup to iCloud ? I am using NSUbiquitousKeyValueStore for iCloud, and have custom logic for updates.
So I do not for iCloud backup to mess things up.

By my understanding that is: Library/Caches/.

Because: Documents/ and Library/Preferences/ are backup to iCloud.

Am I correct ?

Was it helpful?

Solution

You shouldn't use /Library/Cache for storing such kind of information. Look what Apple Data Storage Guidelines says:

Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory.

You can save all your data to /Documents, just flag it so that it wouldn't copy to iCloud:

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
        forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }

    return success;
}

You can use this method in your AppDelegate or wherever you create these files. Note that you can exlude from iCloud backup not only specific files, but directories too.

OTHER TIPS

You can also exclude the specific game data from performing backup to iCloud.

NSURL *url = [NSURL fileURLWithPath:fileName];
assert([[NSFileManager defaultManager] fileExistsAtPath:fileName]);

NSError *error = nil;
BOOL success = [url setResourceValue: [NSNumber numberWithBool: YES]
                              forKey: NSURLIsExcludedFromBackupKey error: &error];
if(!success){
    NSLog(@"Error excluding %@ from backup %@", [url lastPathComponent], error);
}
return success;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top