Report score on Game Center leaderboard

A quick one…

many of you – nay, many of us – shared this problem while developing a game on iOS : you’ve set up properly the Game Center Leaderboard for your application, you log in on your device’s GameCenter Sandbox, you try to report scores, the debugger chills, no problem at all, but no score shows up, the leaderboard remains empty as a geek’s fridge (except for some mustard, although nobody knows exactly why).

You’ve been told many things :

  • you need to cast your score as an int_64t, whatever that may be (that’s actually correct);
  • you need more than one account on your sandbox to have the scores displayed (that’s absolutely not mandatory);
  • you suck (well…some of you do).

I found the answer, but i won’t take credit for that, because it was completely unexpected.

Get it right on iTunesConnect

When you create a leaderboard for your app on iTunesConnect, you set a couple of things, including :

  • its reference (aka Leaderboard reference);
  • its id (aka Leaderboard ID).

Right now, that doesn’t help, but you’ll see in a minute that, sometimes, it’s all about the words…

Report the score on your Leaderboard

You’ve seen those couple of lines everywhere; it’s so easy, it’s actually boring. To report score on your GameCenter Leaderboard, you need to initialize a GKScore, set the score and send the whole thing; you need not to worry about the user, about being authenticated (well, you need to, but not here !). It’s great ! It’s got a giant Apple on its ass for being so good. For the sake of it :

- (void) reportScore: (int64_t) score forCategory: (NSString*) category {
    GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
    scoreReporter.value = score;

    [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
        if (error != nil) {
            // handle the reporting error

BTW, read this page, it’s quite complete…
You’ve seen this code on many forums, but nobody never bothered to ask :
Well, when you initialize your GKScore with the category, WTF is the category ?

Good question; as far as i know, about 1/3 of the people get it wrong about it. For a while, i thought that the category was the leaderboard reference (because « category » doesn’t sound as a unique item that would be used to identify it).

It turns out category IS ACTUALLY the leaderboard id.

Let’s get it loud and clear for the google bots outside :

CATEGORY == Leaderboard ID

When i fixed this, the Sandbox Game center started working fantasticulously (i know it’s not a word…i don’t care) !

By that, i mean : scores get posted instantly, with only one sandbox account (in your face, you elusive doppelgänger of mine…)


Anyway, hope that will help. If so, please leave a message, so that i know i’ve been helpful to one and probably will rot in hell a bit less time. You can also visit the page of my own iPhone game app : WarpOut :

Les commentaires sont fermés.