As a record result in a game center with fast

I'm trying to tell my record in the game center. I think my code works, but the game center is not updated with a record. A leaderboard is created with this link name: "funfairBalloon" and this leaderboard ID ID: 55009943. I have 3 sandbox testers, the game center is on, and the players are authenticated in the game center.

and my code for authentication and report sending:

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?

+6
source share
2 answers

It’s best to add your app id to the leader id. I had problems so that it does not work before that. You may have the same problems. Make a leaderboard with the name "com.whateverName.55009943" and update your code. See if this works the way it was for me.

If you use Test Flight for your sandbox testers, be sure to add them also in iTunes.

Finally, this link should help you resolve the misunderstanding of why you don’t see anyone appearing in the leaderboard if you followed the above tip.

+3
source

You can take a look at this logic in this github repo https://github.com/jocelynlih/SwiftGameBook/blob/master/PencilAdventure/PencilAdventure/ScoreManager.swift#L26

To report the account you need to call, execute the Handler authentication function and in this case, if localPlayer is authenticated, specify the report.

var localPlayer = GKLocalPlayer.localPlayer() localPlayer.authenticateHandler = {(viewController : UIViewController!, error : NSError!) -> Void in if viewController != .None { // Show view controller } else { if localPlayer.authenticated { var scoreToReport = GKScore(leaderboardIdentifier: "Leaderboard\(level)", player: localPlayer) scoreToReport.value = Int64(score) GKScore.reportScores([scoreToReport], withCompletionHandler: nil) } else { // User not authenticated } } }

0
source

Source: https://habr.com/ru/post/979143/


All Articles