I am creating a game using swift on apple's Xcode 6 beta 6, and trying to add the high score of my game to gamecenter leader boards. I have created the leader boards in gamecenter.
So, how do I add my high score, which I saved as a NSUserDefault, to my gamecenter leader boards?
I tried using :
GKScore.reportScore([highScore], withCompletionHandler: nil)
but it just crashes. The initLeaderboard func has been deprecated in ios 8 so I'm not sure what to do.
iOS Configurations Now you need to go to the iTunes Connect, Then select your app, then select features, then Game Center, now from here you can add an achievement or a leaderboard it's a very simple process.
From the app home page, select the horizontal tab “Services” and the vertical tab “Game Center” to access the Game Center Settings. Under “Leaderboard”, click the + to create a new leaderboard. Select either a “Classic” or “Recurring” leaderboard and fill out the rest of the prompts.
First you have to create the GKScore object. Then you set the gkScore.value. Finally, you report the score.
// if player is logged in to GC, then report the score
if GKLocalPlayer.localPlayer().authenticated {
let gkScore = GKScore(leaderboardIdentifier: "leaderBoardID")
gkScore.value = score
GKScore.reportScores([gkScore], withCompletionHandler: ( { (error: NSError!) -> Void in
if (error != nil) {
// handle error
println("Error: " + error.localizedDescription);
} else {
println("Score reported: \(gkScore.value)")
}
}))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With