Save game data into iCloud via GameKit

て烟熏妆下的殇ゞ 提交于 2020-01-02 03:59:24

问题


I'm trying to save game's data to iCloud via next code:

GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer saveGameData:[NSData dataWithBytes:rawData->data() length:rawData->size()]
                 withName:[NSString stringWithUTF8String:fileName.c_str()]
        completionHandler:^(GKSavedGame *savedGame, NSError *error) {
            if (error == nil) {
                DebugLog(@"Snapshot successfully saved");
            } else {
                DebugLog(@"saveSnapshot error: %@", error.description);
            }
        }];

But getting error message: The requested operation could not be completed because you are not signed in to iCloud

I've tried to do this in iOS Simulator and on device but didn't succeed.
And tried to use test apple ID, dev apple ID, new apple ID, but didn't succeed too.
User is logged in to iCloud in iOS Settings and logged in to Game Center.

Any suggestions?


回答1:


I had a similar issue. After I signed in with my iCloud account on my device's settings, the exact same error was still showing up, and it only stopped when I enabled the iCloud Drive for my account, otherwise it will never work.

So, it looks like the user must be using iCloud Drive, otherwise GKSavedGame will never work. Apple docs never mention that as far as I'm aware.




回答2:


  1. Prerequisite:

    • You must have an Apple ID.
    • Check you have your Capabilities set.

      Capabilities > iCloud > ON
      (You must have iCloud Documents checked.)

      Capabilities > Game Center > ON

  2. Go to iCloud and create your account

    • From your computer browser, just login with your Apple ID and accept the terms and conditions. Like here: https://www.icloud.com/#settings
  3. Now you can log in with your device or simulator, in Settings > iCloud.



来源:https://stackoverflow.com/questions/27273072/save-game-data-into-icloud-via-gamekit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!