[SOLVED][ish] [ios] Game hangs when not logged into gamecenter

I’m not sure if this is something I am doing wrong…

I integrated the openfl gamecenter library, and it works great on all ios devices I have tested… as long as I am logged into gamecenter. If i’m not logged in, it hangs on a black screen.

By testing a bit by moving the background music play calls, I narrowed it down to this function… My assumption is it’s hanging on the authenticate call?

private function ConnectToGameCenter()
	GameCenter.addEventListener(GameCenterEvent.AUTH_SUCCESS, onGC_authSuccess); 
	GameCenter.addEventListener(GameCenterEvent.AUTH_FAILURE, onGC_authFailure);
private function onGC_authSuccess():Void 
    userText.text = "Welcome " + Reg.storedUserName + "!";
private function onGC_authFailure():Void 
    userText.text = "GameCenter not available, but I love you anyway!";

Any help would be appreciated. Thanks!

Hmm, I wonder if anyone else has had this issue. Do you check for if (GameCenter.available)?

Yes, I did try that yesterday, and no difference. I also noticed in Xcode that the line

NSLog(@“Authenticating local user…”);

Was being printed twice in a row in my one call. Which leads me to believe isGameCenterAvailable is returning true… At least twice…

Starting to think its in some way related to the gc login, maybe being covered by something. Gonna play with that idea tonight.


Ok… so… I think I managed to hack it into submission.

Problem is in GameCenter.mm, in the authenticateLocalUser() function

[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error)
	NSLog(@"Game Center: You are logged in to game center.");
	sendGameCenterEvent(AUTH_SUCCESS, "");
    else if(error != nil)
	NSLog(@"Game Center: Error occurred authenticating-");
	NSLog(@"  %@", [error localizedDescription]);
	NSString* errorDescription = [error localizedDescription];
	sendGameCenterEvent(AUTH_FAILURE, [errorDescription UTF8String]);
	[errorDescription release];

There’s another possibility here, that the user wasn’t authenticated, and there was no error… which means not logged into gamecenter. This causes the gamecenter login screen to appear, and this is not being handled. Looks like it’s launching the screen, but not showing it properly, and that causes all hell to break loose.

Adding this to the end of the if else chain resolves this issue . (Though full disclaimer, this line of code represents about 98% of my objective C experience, and there probably is a righter way to do it. This does work, however)

else if ( viewController != nil )
    NSLog(@"Game Center: User was not logged in.  Show Login Screen.");
    UIViewController *glView2 = [[[UiApplication sharedApplication] keyWindow] rootViewController];
    [glView2 presntModalViewController: viewcontroller animated : NO];

I’ll add this as an issue to the gamecenter page, but wanted to post it here in case anyone else runs across it.

1 Like