Problem with Gamecenter leaderboards

Discussion in 'iOS Programming' started by solinari6, Dec 16, 2014.

  1. solinari6 macrumors member

    Aug 13, 2008

    I'm working on a simple game with gamecenter support, writing it in SWIFT. I've got a lot of gamecenter stuff working so far:

    1) Authentication works!
    2) Achievements work
    3) Submitting high scores works

    Where I'm running into problems, is retrieving the high scores. I've got 2 test users, who have both logged in and played the game, and submitted high scores.

    When I call code to get a list of all the high scores, I'm only getting 1 high score back ... the score for the logged in user. I'm not seeing anything for the second user. I think this is because the 2 test users are not "friends" (I actually am not sure how to even make them friends).

    From what I see on the doc, the problem is when I request the leaderboard, I have to set the playerScore to Global instead of FriendsOnly. But I am already doing that, and it doesn't seem to have any effect at all. Does anyone know if there's a trick to this? Here's the code:

    let leaderBoardRequest = GKLeaderboard()
            leaderBoardRequest.identifier = "main_leaderboard"
            leaderBoardRequest.playerScope = GKLeaderboardPlayerScope.Global
            leaderBoardRequest.timeScope = GKLeaderboardTimeScope.AllTime;
            leaderBoardRequest.loadScoresWithCompletionHandler { (scores, error) -> Void in
                if (error != nil) {
                    println("Error: \(error!.localizedDescription)")
                } else if (scores != nil) {
                    let localPlayerScore = leaderBoardRequest.localPlayerScore
                    println("Local player's score: \(localPlayerScore.value)")
                    println("High score: \(leaderBoardRequest.scores.first)")
                    println("All scores: \(scores)")
  2. solinari6 thread starter macrumors member

    Aug 13, 2008
    Well I figured out the problem, figured I'd post it in case anyone else sees this.

    Gamecenter sandbox is kind of wonky ... you need more than 2 users for things to really start working. I created a bunch more users, and logged in to my app with them and played the game. Once I had done that with 4 total users, then gamecenter started working correctly, and returned the FULL list of high scores.

  3. Sean7512 macrumors 6502a

    Jun 8, 2005
    As you said, the GameCenter sandbox is really bad. When I was making my game, I had lots of weird issues -- none of which were in my shipping app :)
  4. solinari6 thread starter macrumors member

    Aug 13, 2008
    It is very frustrating. I've created a second leaderboard, and this one is stuck in "you can only see your own scores" no matter how many users I have play the game. Lame. How are we supposed to make sure this stuff will work correctly when we launch?

    So I've got another gamecenter question: This second leaderboard I've created is for a daily puzzle. Every night at midnight PST, the game will start serving up a new puzzle. I want to track the scores of that puzzle for only that day. So I thought I'd use the timeScope, of the leaderboard API to get only that days scores.

    But it's super vague on what "daily" scores are. I've read some implications that it's all scores in the last 24 hours, which wouldn't work. Even if it is just scores for the current date, how does it deal with timezones? Seems like someone playing in a time zone different from PST would end up getting their scores misaligned with the puzzle of the day.

    So I think i'd have to request the top 100 scores or so, and look at the date of each one. Convert that date to PST, and then throw out all the scores that don't land on the right date. Does that sound right? Or is there an easier way to deal with that?

    And how the heck can I test that I get this working, if I can only see 1 score in the freakin leaderboard?!!? ARgh! :(:mad::p

Share This Page