[Solved] Game Center authentication window not appearing?

I have a Cocos2d-x project integrated with Game Center on iOS. To provide the integration I’m using the Game Sharing project. Are there any common reasons - BESIDES the multiple login rejection lockout - that a project would not show the login window at runtime if the user wasn’t authenticated? I haven’t modified any of the controller or delegate code to affect a View other than what is seen in the Game Sharing project.

I’ve tested on a development phone, and everything for Game Center works perfectly IF I am already logged in. The welcome banner appears and scores are uploaded to the leaderboard (and the View to see the leaderboard appears when summoned). But if I’m not already logged in, no window appears. I tested on another app, then mine, then another, and for the other apps the request to log in appeared.

I’m using Cocos2d-x v3.10, developing on Xcode for an iOS target. Tests are run using a connected iPhone at compile and run time.

Code is incomplete in Objective-C++/GameCenterHelper.mm:

Should be something like this:

bool GameSharing::signInPlayer(){
    GKLocalPlayer *player = [GKLocalPlayer localPlayer];
    bool signedIn=false;
    player.authenticateHandler = ^(UIViewController *viewController, NSError *error){
         //Present auth view controller
         if (viewController != nil && error == nil) {
              UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
              [rootVC presentViewController:viewController animated:YES completion:nil];
         }
    };
    if (player.isAuthenticated) {
        signedIn = true;
    }
    return  signedIn;
}

Confirming that this worked. Thanks!

Ok, now I’m confused (easily done).
I too am using the GameSharing (which is great, but the documentation on how to implement is appalling, there’s 2 places where he’s written instructions - and they differ from each other!!!).

I’ve not checked to see if it works with the player signed out, until now…

The code as it was appears to work fine on my iPod Touch.
So, I’ve replaced the GameSharing::signInPlayer() function with the one above, and it crashes calling [rootVC presentViewController:viewController animated:YES completion:nil];

:frowning:

Whoops @JohnnyC, that’s my mistake.

Here’s my thought process that led to my last response.

At the time the solution was posted, Game Sharing made no effort at all to present a view controller, so I saw that the suggestion required one, and then implemented one in a PR, which is what you saw when you used it. I didn’t specifically check the presented implementation, which is completely my bad.

For everyone stumbling onto this thread…ignore it! Game Sharing is patched and works great now!

1 Like