Save game data to iCloud via GameKit

I am trying to save game data in iCloud through the following 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 an error message: The requested operation could not be completed because you are not signed in to iCloud

I tried to do this in iOS Simulator and on the device, but failed.
And tried to use the test apple id, apple apple id, new apple id, but also failed.
The user connected to iCloud in the iOS settings and entered the Game Center.

Any suggestions?

+5
source share
2 answers

I had a similar problem. After I registered in my iCloud account in the settings of my device, the exact same error still showed up, and it stopped only when I turned on iCloud Drive for my account, otherwise it will never work.

So, it looks like the user should use iCloud Drive, otherwise GKSavedGame will never work. Apple docs never mention this as far as I know.

+1
source
  • Prerequisite:

    • You must have an Apple ID.
    • Check if your features are installed.

      Features> iCloud> ON
      (You should have verified iCloud documents.)

      Features> Game Center> ON

  • Go to iCloud and create your account

  • Now you can log in using your device or simulator in Settings> iCloud.

0
source

Source: https://habr.com/ru/post/1208236/


All Articles