简体   繁体   English

建议在没有iCloud支持的情况下保存iOS游戏数据的地方

[英]Recommended place to save iOS game data without iCloud support

What is the recommended place to save game data if I do not want automatically to be backup to iCloud ? 如果我不想自动备份到iCloud,建议在哪里保存游戏数据? I am using NSUbiquitousKeyValueStore for iCloud, and have custom logic for updates. 我正在为iCloud使用NSUbiquitousKeyValueStore ,并且具有用于更新的自定义逻辑。
So I do not for iCloud backup to mess things up. 因此,我不希望将iCloud备份弄乱。

By my understanding that is: Library/Caches/ . 据我了解是: Library/Caches/

Because: Documents/ and Library/Preferences/ are backup to iCloud. 因为: Documents/Library/Preferences/已备份到iCloud。

Am I correct ? 我对么 ?

You shouldn't use /Library/Cache for storing such kind of information. 您不应使用/Library/Cache来存储此类信息。 Look what Apple Data Storage Guidelines says: 看看苹果数据存储指南说的是什么:

Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. 可以再次下载或重新生成的数据应存储在/ Library / Caches目录中。

You can save all your data to /Documents , just flag it so that it wouldn't copy to iCloud: 您可以将所有数据保存到/Documents ,只需对其进行标记,以使其不会复制到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. 您可以在AppDelegate或任何创建这些文件的位置使用此方法。 Note that you can exlude from iCloud backup not only specific files, but directories too. 请注意,您不仅可以从iCloud备份中排除特定文件,还可以从目录中排除。

You can also exclude the specific game data from performing backup to iCloud. 您也可以将特定游戏数据排除在执行备份到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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM