6

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!

Edit

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.

Community
  • 1
  • 1
Tim Arnold
  • 8,359
  • 8
  • 44
  • 67
  • Is it possible that these users have Game Center disabled? If you cancel logging in to GC for 2-3 times in a row, the device prompts you to disable it. After that you can only sign in manually, the app won't show the GC auth dialog anymore. – nikolovski Mar 25 '13 at 15:46
  • @MarkoNikolovski thanks for the suggestion. I've read about that behavior (see linked question in my edit), and suspected it might be my problem. I don't think I cancelled log-in repeatedly, but regardless, it's possible that's why my auth dialog isn't showing up. My problem though, is: how to log in to the sandbox with Game Center app when it doesn't offer "sandbox" in the password placeholder field? – Tim Arnold Mar 25 '13 at 15:49
  • It turns out the problems were mostly due to a mistake I made in my `authenticateHandler` code, where my logic wasn't properly presenting the `viewController` to the user so they could log in. Insofar as there were still some confusing issues surrounding presenting the view controller and Game Center being "disabled", @MarkoNikolovski's answer is helpful and correct, so I have marked it as the answer. – Tim Arnold Mar 25 '13 at 17:57
  • Thanks, glad I could of help. – nikolovski Mar 25 '13 at 19:10

1 Answers1

1

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.

nikolovski
  • 4,049
  • 1
  • 31
  • 37
  • Thanks for the link to listing 3-1. I think in a production environment, you are right, checking for this and telling the user "go to Game Center app and log in manually" would definitely work. Pretty sure that some experiencing this error (including myself) did *not* tap "cancel" on the dialog a few times. Is there another way Game Center can become disabled? Additionally: any idea how to get a sandbox login prompt in the Game Center app to overcome GC being "disabled"? – Tim Arnold Mar 25 '13 at 16:04
  • TL;DR: I'm stuck unable to test my app because I can't get Game Center to show me a sandbox login to override GC somehow being "disabled", if this is indeed what is going on. – Tim Arnold Mar 25 '13 at 16:06
  • Can you login to Game Center at all, regardless if it's sandbox or not? Also, are you doing this in the simulator or on a device? – nikolovski Mar 25 '13 at 16:14
  • On a device. I can successfully log in to a production Game Center environment. One idea: create a new app in iTunes Connect and the Provisioning Profile for the sole purpose of having a "fresh" Game Center sandbox login prompt, if the GC "disabled" state is a per-app state. – Tim Arnold Mar 25 '13 at 16:21
  • That sounds like too much work. I'm sure this shouldn't be that complicated. #famouslastwords – nikolovski Mar 25 '13 at 16:25
  • Is your production and sandbox accounts on the same e-mail/iTunes account? – nikolovski Mar 25 '13 at 16:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/26880/discussion-between-tim-arnold-and-marko-nikolovski) – Tim Arnold Mar 25 '13 at 16:27