GKLocalPlayer fetchSavedGamesWithCompletionHandler returns 0 games on installation
Asked Answered
C

1

11

I can save my game and also fetch it but if I uninstall the game and then install it again, the call to fetchSavedGamesWithCompletionHandler returns 0 games (even if I call it several times). And if I call it again after some few seconds, the GKLocalPlayer manages to fetch the game i previously saved.

The error is nil so there is no problem with connecting to Game Center or iCloud (if there was problem with iCloud, the error wouldn't be nil and it would say that the user isn't connected to iCloud or that iCloud Drive isn't on).

This is not the same if anyone thought of sharing that with me: https://stackoverflow.com/questions/34445258/gklocalplayer-fetchsavedgameswithcompletionhandler-result-depends-on-device

Sure I can just fix it by implementing a timer and then call fetchSavedGamesWithCompletionHandler accordingly, but that's just a bad way of fixing it considering that the game is gonna support the slower devices (iPhone 5s compared to iPhone 7).

Cooperstein answered 6/12, 2016 at 9:56 Comment(10)
Did you find the answer or solution to this problem? I also have this weird problem and have no clue how to handle it.Unclassified
Nope I'm sorry. Had other stuff to do at the same time and so at a later date, iCloud was scrapped. Right before it was scrapped, I thought of making my iCloudmanager to poll for saved games and then update the game with the saved game if it manages to fetch a saved game. It would almost be the same as setting a timer but this would be more versatile I guess since it isn't dependent on time but on state change... That would at least be my solution (if it works) if we pick up the iCloud thing again.Cooperstein
I'm facing same problem, do you have some idea?Lang
Facing Same problem -- xcode 10.2.1. Swift 5Weigh
Facing same problem , Xcode 11.3, anybody?Thimbu
😕 same issue Xcode 13.3.1Callis
I know that this is a few years late, but: Hello, I'm the new engineering manager for GameKit. We're working on fixing many authentication-related issues this year. Could you provide a little bit more debugging information? Are you attempting to call fetchSavedGamesWithCompletionHandler from inside the authentication handler? Or independently, after already authenticating?Thinskinned
Facing same problem. How to reproduce - 1: Delete App. 2: Install and launch App from Xcode 14.1 with iPad mini 5th iPadOS 15.7. 3: Call fetchSavedGamesWithCompletionHandler from inside the authentication handler. I don't know why but when I use iPhoneXS iOS 16.0, it never occurs. Maybe because I saved my game data from not iPad mini 5th iPadOS 15.7 but iPhoneXS iOS 16.0.Aggri
This thread is related to this issue. https://developer.apple.com/forums/thread/718541Aggri
@BrandonBloom I am experiencing this issue both after an install of my app and when I have conflicting saved games. I can repro semi-reliably by creating a save on my phone, then launching the simulator shortly afterward. I am calling fetchSavedGamesWithCompletionHandler after the auth callback returns. I do not get an error in the handler, but I consistently get several of the following log message every time I see this issue: grantAccessClaim reply is an error: Error Domain=NSCocoaErrorDomain Code=3072 "The operation was cancelled."Concertize
A
1

This is my workaround using sleep.

I call fetchSavedGamesWithCompletionHandler from inside the authenticateHandler using dispatch_async like below.

As for me, sleep for 1.7 or more seconds worked with iPad mini 5th. Sleep for 4.1 or more seconds worked with iPhone5s. Please change it as you like.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

  //[NSThread sleepForTimeInterval:1.7];//minimum for iPad mini 5th
  //[NSThread sleepForTimeInterval:4.1];//minimum for iPhone5s
  [NSThread sleepForTimeInterval:5.0];

  [localPlayer fetchSavedGamesWithCompletionHandler:^(NSArray<GKSavedGame *> * _Nullable savedGames, NSError * _Nullable error) {

    //do something...

  }];
                    
}                    

2023 Feb 3rd: add and modify

I found that returning 0 games can occur not only on installation.

It occurs,

  • When the app is installed.
  • When the game data on iCloud is manually deleted then new data is written.
  • When conflict by offline writing occurs and data is discarded by resolveConflictingSavedGames.

So, we must wait whenever 0 games are returned.

To handle this, if 0 games are returned, retry several times with a few seconds delay.

Required retry count depends on the device specs and other processes running in the App.

To me, iPhone5s - the lowest spec device I have - needs 4 retry with 3 seconds delay.

Aggri answered 22/12, 2022 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.