Game Center Authentication Handler View Controller is always zero

I am trying to set up Game Center in a quick game with a sprite pack. The App Delegate does the following:

func authenticateLocalPlayer(){
    let localPlayer: GKLocalPlayer = GKLocalPlayer.localPlayer()

    localPlayer.authenticateHandler = {(viewController : UIViewController!, error : NSError!) -> Void in
        //handle authentication
        if (viewController != nil){
            self.window?.rootViewController?.presentViewController(viewController, animated: true, completion: nil)
        }
        else{
            if (localPlayer.authenticated){
                gameCenterEnabled = true

                //Get the default leaderboard identifier.
                localPlayer.loadDefaultLeaderboardIdentifierWithCompletionHandler({ (leaderboardIdentifierr: String!, error: NSError!) -> Void in
                    if (error != nil){
                        NSLog("%@", [error.localizedDescription])
                    }
                    else{
                        leaderboardIdentifier = leaderboardIdentifierr
                    }
                })
            }
            else{
                gameCenterEnabled = false
            }

        }
    }
}

      

The problem I am facing is that localPlayer.autheniticateHandler always returns nil viewController even though my local player is not authenticated. Please let me know what I am doing wrong and how to fix it.

+3


source to share


3 answers


I had the same problem.

Try uninstalling the app from your device, then go to your device settings in Game Center and enable sandboxing.



Then launch the game again on the device and display the game center login window.

+9


source


I tried to run my application in the simulator and the authentication window worked fine. I'm not sure why it is not working on my device.



0


source


It's the same for me. Tried multiple devices with the same result. Removing the app / changing Game Center settings won't help. However, your code looks ok. It looks like the GC for Swift is completely broken.

0


source







All Articles