Handle Cancelling Of Game Center Authentication With Prime31 Plugin

Posted by on in Development-Blog
  • Font size: Larger Smaller

If your Game Center enabled app starts the very first time, you have to decide how to handle those situations when the user don't want to connect to Game Center. A call to GameCenterBinding.authenticateLocalPlayer () triggers 3 login requests even if the user pressed Cancel. Here is my workaroung for this using a message box first.

After a call to GameCenterBinding.authenticateLocalPlayer () you delegate control to the iOS SDK, that means there is no chance to suppress the subsequent 2 login prompts everytime the app will enter foreground again. This behaviour occurs regardless whether the user has pressed Cancel. So users with no Game Center account will be annoyed by authentication requests.


To work around this I use a message box at the very first start of the app. The user is asked if Game Center should be used or not:

Message Box

Depending on the answer GameCenterBinding.authenticateLocalPlayer () is either called or not. On the other hand there has to be the possibility to use Game Center later on in case the user denied it before. This is done by an extra button in the local high score list which is used as fallback for non-GC users.


This is neither a perfect solution nor cutting edge technology but the best one I found. Even the guys at Prime31 didn't have a better solution (s. Handle Cancel Login For Game Center). I use the Etcetera plugin from Prime31 to display a native style message box. Edit AuthenticateLocalPlayer to use an alternative way to ask the user.



/// <summary>
/// Handles Game Center connectivity and access to leaderboards and achievements.
/// </summary>
public class GameCenterConnector : MonoBehaviour
    static GameCenterConnector instance = null;
    public static GameCenterConnector SharedInstance {
        get {
            if (instance == null) {
                instance = new GameCenterConnector ();
            return instance;
    /// <summary>
    /// (persistentIndicates whether the message box was shown on very 1st start.
    /// </summary>
    bool initialMessageBoxShown = false;
    /// <summary>
    /// (persistentIndicates whether GameCenterBinding.authenticateLocalPlayer should be called.
    /// </summary>
    bool autoConnect = false;
    /// <summary>
    /// Set temporily when Game Center app is opened to force in-game Game Center auhentication.
    /// </summary>
    bool reconnect = false;

    void Awake () {
        initialMessageBoxShown = false// Read this from your config
        autoConnect = false// Read this from your config
    public void AuthenticateLocalPlayer () {
        if (!initialMessageBoxShown) {
            EtceteraManager.alertButtonClickedEvent += GameCenterMessageBoxCallback;
            string [] buttons = {"Yes""No"};
            EtceteraBinding.showAlertWithTitleMessageAndButtons ("Game Center""Use Game Center?"buttons);
        if (!autoConnect) {
        GameCenterBinding.authenticateLocalPlayer ();
    public void GameCenterMessageBoxCallback (string button) {
        bool autoConnect = button == "Yes";
        initialMessageBoxShown = true;
        if (autoConnect) {
            // we need a 2nd call as this runs in parallel
            AuthenticateLocalPlayer ();
    /// <summary>
    /// Called before switching to Game Center app.
    /// </summary>
    public void ReenableAutoConnect () {
        autoConnect = true;
        reconnect = true;
    void OnApplicationPause (bool pause) {
        if (!pause && reconnect) {
            // weare back from game center apptrigger reconnect
            reconnect = false;
            AuthenticateLocalPlayer ();

Calling Game Center App

I provided a local high score list for those users who don't use Game Center. There is a button to switch to the Game Center app:


Local Score


The event handler of this button contains the following code:

        GameCenterConnector.SharedInstance.ReenableAutoConnect ();
        Application.OpenURL ("gamecenter:/");

This opens the iOS Game Center App and puts RRRunner into the background. When getting to foreground again, GameCenterConnector.OnApplicationPause is called and triggers the connecting process.


Submit to FacebookSubmit to TwitterSubmit to LinkedIn
Rate this blog entry:


  • Steffen Montag, 12 Mai 2014

    Sandbox Mode

    this does not work for testing in sandbox mode, because calling OpenURL redirects out of the App, so GC will not detect my game to be in sandbox mode and signs into gc like a regular account.

    Do you have any workaround for sandbox mode by any chance?

  • Kay Montag, 12 Mai 2014

    RE:Sandbox Mode

    Sorry, but I am sure that it works in sandbox mode. RRRunner 1.x doesn't support Game Center and version 2.0 is not yet released. So I tested everything in sandox mode and hope that it will work in production ;)

Leave your comment

Guest Donnerstag, 29 Juni 2017

Zusätzliche Informationen