6

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?

Haox
  • 608
  • 1
  • 7
  • 23
  • 1
    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. – Scott Dec 06 '14 at 23:10
  • I made a leaderboard on iTunes connect named "com.whateverName.55009943" and update `'leaderboardIdentifier : "com.whateverName.55009943"` but stil have no score and no player on the game center. qmzdcjselrbhvslkvhblqziehbflshbv AAAAAHHHHHHHHH I go crazyyyyyyyy – Haox Dec 06 '14 at 23:19
  • YAHOUUUUUU !!! Thanks to you I found my mistake !! My leaderboard wasn't well set up ! I love you !!!! Looking since 3 days !!!! – Haox Dec 06 '14 at 23:29
  • You have to answer for the +50 reputation :D – Haox Dec 06 '14 at 23:31
  • However is it normal I can't see other players from a sandbox tester in game center? – Haox Dec 07 '14 at 00:06
  • @hoax I'm glad I helped. I've definitely shared your frustration before. I posted an answer. – Scott Dec 07 '14 at 01:14

2 Answers2

3

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.

Scott
  • 1,154
  • 1
  • 12
  • 25
0

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 score you need to call pass the authenticateHandler closure function and in that if localPlayer is authenticated then report score.

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 } } }

Encore PTL
  • 8,084
  • 10
  • 43
  • 78
  • Thanks for your message but I tried with your code and it doesn't work. I tried to understand the logic in the github repo but my knowledge is too weak... I still have the same message : `report score player:playerID:g:F586362F0C610DB51DC5221012AE9D92 alias:Sophie88 rank:0 date:2014-12-05 21:58:29 +0000 value:9 formattedValue:(null) context:0x0 leaderboard:funfairBalloon group:(null)` – Haox Dec 05 '14 at 22:02