문제

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 ?

도움이 되었습니까?

해결책

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.

다른 팁

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top