Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bizarre GameKit behavior. Anyone else seeing this?

I am running Xcode 4.3.3 and am targeting iOS 5.1. I am attempting to include Game Center functionality in a game.

When authenticating the GKLocalPlayer the user is presented with the Sign in to Game Center alert view or shown to be logged in. So far this is all fine, but if the user presses the Create New Account button then any open modal views are moved behind the root view controller and the following error is spit from the console:

Unbalanced calls to begin/end appearance transitions for <GKModalRootViewController: memory address>.

I have tried moving the GKLocalPlayer authentication code between the app delegate and the root view controller. I have also tried implementing the authentication in a new, blank project. I have tried it with and without Storyboards and ARC. In all of these cases the results were the same: modals hidden behind the root view controller and error given.

Here is the GKLocalPlayer authentication method I am calling from my app delegate’s application:didFinishLaunchingWithOptions: method:

- (void)authenticateLocalPlayer
{
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    [localPlayer authenticateWithCompletionHandler:^(NSError *error) {
        if (localPlayer.isAuthenticated) {
            // Perform additional tasks for the authenticated player.
        } else {
            // Disable Game Center features.
        }
        if (error) {
            // Handle error.
        }
    }];
}

Here is a screenshot of it. In this picture the root view controller has a background with a 50% alpha value. The modal has been pushed behind the root view controller by this bug.

This stackoverflow question contains the only reference to this error (regarding GKModalRootViewController) I can find, and it doesn't fit since (a.) I’m not using cocos2d. (b.) It happens whether or not I perform a segue, and I am not touching viewWillAppear: or viewDidAppear:. (c.) No acceptable answer was given.

This question and this one seem to involve the same issue (with the view hierarchy being destroyed) but are unanswered and don’t mention the console error message.

Does this happen for anyone else? Any ideas on what could be causing this?

UPDATE 1: I went so far as to put the authentication code into an IBAction connected to a button in the modal view so as to avoid any initialization conflicts. It didn't help.

UPDATE 2: I tried moving the authentication code into a GCD background queue. he results were the same.

Here is the test project (which is GameCenter ready with my app's Bundle ID already entered).

To test:

  1. Log out of Game Center on the test device/simulator (if you are logged in).
  2. Build and run the app.
  3. Press the info button.
  4. Press Authenticate.
  5. When the Sign in to Game Center alert appears press Create New Account.
  6. Press Cancel.
  7. Did the “Unbalanced calls...” message appear in the console? Did the modal view (with the Authenticate button) disappear?
  8. Press the info button.
  9. Did the modal display again?
like image 995
Endersstocker Avatar asked Jun 20 '12 14:06

Endersstocker


1 Answers

This bug appears on the list of "bugs Apple fixed in 6.0". I understand you would love a workaround, but when its the APIs you depend on that are buggy, chances of that are slim.

You can however rejoice that 5.x users are slowly dying out.

Best of luck with your app.

like image 195
Nils Munch Avatar answered Oct 21 '22 11:10

Nils Munch