Search code examples
iphoneswiftios8xcode6game-center-leaderboard

how report highscore in Game center with swift


I'm trying to report my highscore in the game center. I think my code is working but the game center is not updating with the highscore. The leaderboard is create with this reference name : "funfairBalloon" and this leaderboard ID : 55009943. I have 3 sandbox testers, the game center is enable and the players are authenticated in game center.

and my code to authenticate and to report is :

func authenticateLocalPlayer()
{
    var localPlayer = GKLocalPlayer.localPlayer()

    localPlayer.authenticateHandler =
        { (viewController : UIViewController!, error : NSError!) -> Void in
            if viewController != nil
            {
                self.presentViewController(viewController, animated:true, completion: nil)
            }
            else
            {
                if GKLocalPlayer.localPlayer().authenticated {
                    let gkScore = GKScore(leaderboardIdentifier: "55009943")
                    gkScore.value = Int64(highscore)
                    GKScore.reportScores([gkScore], withCompletionHandler: {(error) -> Void in
                        let alert = UIAlertView(title: "Success",
                            message: "Score updated",
                            delegate: self,
                            cancelButtonTitle: "Ok")
                            alert.show()
                        })
                }
             }
        }
}

Do you have an idea?


Solution

  • It's best practice to add your app id to the leaderboard identifier. I had trouble not getting it to work before then. You may be having the same troubles. Make a test leaderboard named "com.whateverName.55009943" and update your code. See if that works like it did for me.

    If you are using Test Flight for your sandbox testers make sure to add them on iTunes connect as well.

    Finally, this link should help you troubleshoot why you're not seeing anyone show up on the leaderboard if you followed the above advice.