I'm trying to integrate Game Center on a watchOS app but I'm unable to authenticate the Local Player.
Maybe I'm missing any step to allow the companion watchOS app to access Game Center as the iOS app does?
On the watchOS App Extension I'm calling:
GKLocalPlayer.local.authenticateHandler = { error in
}
Which is very similar to the method used to authenthicate on iOS, and on iOS it works, even on the simulator.
When calling that method, and running on a simulator I get this log on Xcode's debug area:
[Error] _authenticateUsingAlert:Failed to authenticate player with existing credentials.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.}
and the error message received on the completion handler is:
Error Domain=GKErrorDomain Code=3 "The requested operation could not be completed due to an error communicating with the server." UserInfo={NSLocalizedDescription=The requested operation could not be completed due to an error communicating with the server.}
When testing the same scenario on a real device I get the log:
[Error] _authenticateUsingAlert:Failed to authenticate player with existing credentials.Error: Error Domain=GKErrorDomain Code=15 "The requested operation could not be completed because this application is not recognised by Game Center." UserInfo={GKServerStatusCode=5019, NSUnderlyingError=0x11e3a6c0 {Error Domain=GKServerErrorDomain Code=5019 "status = 5019, no game matching descriptor: ios:com.myApp.test.watch.extension::0+-1" UserInfo={GKServerStatusCode=5019, NSLocalizedFailureReason=status = 5019, no game matching descriptor: ios:com.myApp.test.watch.extension::0+-1}}, NSLocalizedDescription=The requested operation could not be completed because this application is not recognised by Game Center.}
and the error from the completion handler is:
Error Domain=GKErrorDomain Code=15 "The requested operation could not be completed because this application is not recognised by Game Center." UserInfo={NSLocalizedDescription=The requested operation could not be completed because this application is not recognised by Game Center.}
Both these errors are similar to the messages you get on iOS when the app hasn't enabled Game Center on App Store Connect. As mentioned before this is not the case as on iOS works fine.
I also tried moving the app to a Game Center Group on App Store Connect, as it says this is meant to share leaderboards and achievements, but the result was the same.
After weeks of pulling my hair I found out (the hard way) that Game Center works on watchOS only when on a real device, and it works very limited.
You can access the local player display name but you can't submit scores.
I even tried adding the app to Game Center Groups, it didn't help.
--
PS. It will still show error messages and warnings on Xcode's console saying that user is not authenticated or that app is not recognised by Game Center, but it will work if you try to get GKLocalPlayer.local.displayName after authenticating with GKLocalPlayer.local.authenticateHandler. It also apparently will submit scores to leaderboards or at least will show no error, but the scores never get submited.
Unfortunately it seems that authenticating to Game Center on watchOS with GKLocalPlayer.local.authenticateHandler currently does not work properly and therefore it is not possible to report scores directly from watch app or at least it did not work for me even on a real watch device with a live app with working game center leaderboard (working on ios).
As an alternative solution you could save scores on watchOS locally for example to UserDefaults and transfer them to companion iOS app if you have one. For transfering that data you can use WatchConnectivity framework that offers WCSession class with updateApplicationContext method which you can use on your watch device and on ios device receive that data using func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) delegate method. Then when you have the score on ios app you can send it to game center as usual from ios app. This unfortunately requires that user also launches ios companion app from time to time but it is better that nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With