Game Center Sandbox Sign In

This is a tale of woe about the perils of Game Center Sandbox sign in.

For those who want to cut to the chase… Xcode may point your app at the live Game Center servers in error, if so delete the app and try again. If you decline to sign in to the Game Center Sandbox you can find yourself locked out with no way to get to a sign in prompt. A solution is to reinstall iOS on your device and try again.

For those who like the torturous details, read on…

When you test a Game Center enabled app it uses a test version of Game Center, the "Sandbox". In principle, and often in practice, it is simple - you create a test account, log out of Game Center on the device, run your app from Xcode and sign in to the Sandbox with your test account when prompted. Do this on multiple devices and you can play a multiplayer game within the sandbox. Easy.

You do not have explicit control over whether you are accessing the live Game Center servers or the Sandbox servers. When you run an app from Xcode it should always point you at the Sandbox. Once you have signed in to the Sandbox via an app the Game Center app will also access the Sandbox. There is no way to explicitly open the Game Center app pointing at the Sandbox. And this is where the fun can begin.

My problems started when I fired up a test version of Racing Demon and was asked to sign in to Game Center with my live account details. This was a surprise as I had previously been happily using a test account on that device so no sign in should have been required. If sign in was required would have expected it to have prompted me with my test account. The dialog also did not include the "Sandbox" tag so it appeared that I was being pointed at the live servers. After a bit of poking around it became obvious that I was indeed using the live Game Center servers, even though the app was started from Xcode.

So the problem became how to point the app at the Sandbox servers. The solution was to delete the app from the device and reinstall from Xcode. A quick, simple, painless solution.

A few days later I had a similar problem, but with a twist that made it more painful. I was again prompted to sign in with my live id. As before I signed in, but was presented with some Game Center set up screens (e.g. terms and conditions, and setting an alias). As my live id is already setup in the live version of Game Center it appeared that I was being pointed at the Sandbox servers. This is what Xcode is supposed to do, the only issue was that I was not using my test account.

The Apple documentation warns against using a live id on the Sandbox servers (without specifying any consequences), so I cancelled out of the sign in process. This was my "big mistake".

Game Center is design to avoid annoying a user with repeated sign in prompts. If you decline to sign in from an app Game Center will not present the sign in dialog again. If you want to use Game Center with that app at a later time you simply sign in through the Game Center app and then go back the game app. That works fine in the live world, but not in the Sandbox.

If you are not signed in to the Sandbox environment the Game Center app comes up in live mode. There isn't a way of telling the Game Center app that you want to sign in to the Sandbox. Since you have previously declined to sign in from your app you will not be prompted to sign in from the app again.

This behaviour in your app is controlled by Game Kit, and there is no obvious way to over ride it (and you would not want to in production).

So I was signed out of Game Center with no way to sign back in to the Sandbox. The Game Center app would only sign me in to the live system and my app wasn't going to ask again. Of course this also meant I couldn't use any of the Game Center functions in my app so testing was impossible.

I needed to find a way to get Game Center to forget my previous declined sign in so that it would prompt me to sign in again in Sandbox mode. I tried Googling my problem. I re-read the documentation. I tried deleting and reinstalling as per the previous problem. I tried deleting the app and restarting my device and Mac before reinstalling. I tried fiddling with the code signing settings and my build schemes (OK I was getting a little desperate). I tried doing an iTunes backup and restore of the device (which just restores settings and data). I tried restoring to factory settings and restoring from backup. None of this worked.

Finally I tried restoring to factory settings (i.e. reinstalling iOS) and configuring it as a new device. Only this last, fairly extreme, option worked!

To clarify there are two separate issues here:

  1. Xcode will sometimes start an app and point it at the live Game Center servers. This is clearly a bug, but has a painless work around (delete and reinstall). I don't know what triggers it, but so far I have only seen it under iOS 7, and only with an app that has an earlier version in the App Store. Another test device under iOS 5 has remained happily signed in and pointing at the Sandbox through out.

  2. If you decline to sign in to the Sandbox through an app it will not ask you again and you will not be able to sign in to the Sandbox through the Game Center app. This isn't a bug as such as all components are working as advertised. Being charitable it is a design oversight that there is no easy way to get back to a Sandbox sign in prompt. Unfortunately the fix is not as simple as a delete and reinstall, but is relatively painless on a development device.

I take three lessons from this experience:

  1. You can not be sure which Game Center environment Xcode will point you at, regardless of what the documentation says. So always proceed with caution.

  2. Never decline to sign in to the Sandbox environment. The documentation doesn't specify what evils will befall you if you sign in to the wrong environment with the wrong id, but I am willing to risk it to avoid this problem recurring.

  3. If you use a device for development and testing, be ready to take it back to bare iOS. While I didn't lose any data doing this I haven't gone through all of the steps to reinstall apps, customise settings, resych music etc to get my device back to the way I would ideally want it for personal use. This would be wasted time if I end up having to restore again soon.

If anybody has found a more palatable solution to this second situation I would love to hear about it. I wonder whether accessing a second, unrelated Game Center enabled app through Xcode could help, but I have not tried it.