2

I have an turn-based game using GameKit in iOS. Generally, my authentication with Game Center works. My game works and I can for periods of time send moves back and forth. However, relatively frequently but not constantly, when I try to perform an action (e.g., finding a new match) over Game Center it fails with the error:

Error Domain=GKErrorDomain Code=6 "The requested operation could not be completed because local player has not been authenticated." UserInfo={NSLocalizedDescription=The requested operation could not be completed because local player has not been authenticated.}

Yet, the GKLocalPlayer.localPlayer().authenticated = true, both immediately before getting the error and after. After getting this error, the authentication viewController does not get presented and GameKit methods that rely on authentication cease to function (they don't come back to life ). Then, if I send the app to the background and then bring it back to the foreground, the error does not return when I retry the action (without requiring new login and password entry).

According to this similar observation:

GKLocalPlayer authentication not working, but isAuthenticated returns YES (Game Center sandbox)

"1.Game Center fails to complete authentication if your device has incorrect dates. So, go ahead and check the current date.

  1. You might have done this. I trust you - iOS Simulator >> Reset Content and Settings"

I am getting this problem on the device, not the simulator, ruling out #2. Could someone help me with #1? I may be naive here, but my iPhone and iPad have the right time and date. Is there something or somewhere else I should be checking and setting?

Then, if this is not the issue, what else could be the problem? I am running iOS9.

Community
  • 1
  • 1
cdub
  • 180
  • 1
  • 12
  • Did you figure out how to resolve this? I'm getting this error in my game. – Luke Irvin Dec 01 '17 at 23:43
  • It doesn't seem to be a huge problem for me anymore, but every once in a while my app does fail to authenticate. When that happens the only way I know of to resolve it is to close the app and open it again. I was not successful in re-authenticating while the app was still running when getting the error. Also, .authenticated = true cannot be relied on in general when things are going poorly. – cdub Dec 03 '17 at 02:28
  • I am experiencing the exact same problem. Does this problem only occur in sandbox or in the live environment as well ? Can I assume that my code ist OK, when runs successful in sandbox at 70% of the cases ? I can't see any reason why it works now and next time under exact same conditions it does fail. Any ideas ? – Chris Jan 29 '18 at 11:42

1 Answers1

2

I've seen this too, and have an open bug with Apple. In my case, I'm testing with multiple physical devices, and only one of those devices ever encounters this. On that particular device, I'm logged into iTunes using a personal account, but logged into game center using a test account.

From what I can see, when the device is using the same login for iTunes, iCloud and game Center, there are no problems. But, when I try to mix-and-match the accounts for whatever testing I need to do, then I randomly get error 6.

There doesn't seem to be anyway to recover from this, except to have the user re-login into game center. Of course, there's no way to present the login view controller again, so the only option is for the user to leave the game, kill it off, and star up again (which re-starts the game center authentication process). I trap the error now, give the user a message saying Game Center has logged them out, and explain what they need to do about it.

But as I said, when I stopped mixing up credentials on the device, the problem went away.

BTW, on a slightly related topic, I've come to view the .authenticated property as completely unreliable. It will be TRUE in conditions where you do not actually have connection to Game Center. I opened a bug on this, too. Apple closed it saying this was working as intended by using "cached" data. Thus, it will report authenticated when it's not authenticated and give you access only to outdated match and leaderboard data which had previously been saved locally.

Thunk
  • 4,099
  • 7
  • 28
  • 47
  • Thanks. I am not currently mixing credentials and still get the same problem. There is something to your observation though. I have seen other issues when using mixing and matching accounts. I don't know what all is cached, but my test device has in the past used several accounts for GC and perhaps previous logins can also cause this. Just an unfounded guess. GC I love you. – cdub Oct 17 '15 at 19:43
  • Thanks! Your statement about "I've come to view the .authenticated property as completely unreliable. It will be TRUE in conditions where you do not actually have connection to Game Center... [etc]" was the key to my issue. Turns out a good test for any Game Center code is to be logged into GC, but in airplane mode, so actual calls for data won't complete. – eddybox Jun 14 '22 at 23:46