I'm having some seriously confusing Game Center problems.
My app runs on iOS 6 and above only, and I've been using the standard code for authenticating with Game Center:
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController,
NSError *error) {
// Respond to authentication (failure or success) here!
}
With this code, the app has been running beautifully and without issue for weeks, for myself during development and with ~10-15 beta testers in ad hoc distributions.
For most of this time, and for most users, the app behaves as you expect: if you aren't logged into Game Center when the app launches, or are logged into a production Game Center account, the app prompts you (with the modal Game Center-themed View Controller) to log in with a Sandbox account. You log in to your sandbox account, and everything Just Works.
For a few users, though, something very strange has begun to happen.
The authenticateHandler
code is called, error
is nil
, but [GKLocalPlayer localPlayer].authenticated
is NO
, and the user is not logged into Game Center. Most important, there is no modal Game Center dialog to prompt the user to log in. The app simply launches, the authenticateHandler
code is called, but no authentication takes place. I think the app would work if the Game Center app would allow me to log in with my sandbox account, but it doesn't: logged in or out of my production Game Center account, there is no sandbox log-in option.
Since this only happens to some users, and has only begun to happen for my development device, I very much doubt that it's a problem with my code, and am guessing it is some complex interplay between iTunes Connect, provisioning profiles, Game Center's settings and history on the device, etc.
Game Center is enabled in our App ID and in iTunes Connect (and App IDs for both match).
Help!
My problem may be similar to iOS Development: Strange problem with authenticating Game Center user. The solution proposed for that question was to sign in manually in the Game Center app. This seems like a sensible solution, but I need to log in to the sandbox environment, and I can't find a way to get a sandbox Game Center login prompt in the Game Center app.
I just tried on my device what happens if the user has disabled Game Center: the user cannot get to the Game Center login view controller anymore from inside the app. You need to post some instructions for the user to manually login.
I also went to Game Center manually and logged in to my account (my regular account with my regular iTunes account) and after going back to my app I was authenticated back automatically without an additional prompt. I'd wager that if you have a separate e-mail/account for the sandbox GC account you'll just get the auth dialog again.
TL;DR: put some instructive text what the user should do if you cannot get the modal dialog. Look at Apple's code in the GameKit programming guide (PDF page 36, listing 3-1). You need to execute this code in the else
part.