Search code examples
ios9game-centerleaderboard

Display Specific Leaderboard in Game Center?


In my iOS9 project, I have a total of 8 leaderboards associated with Game Center. I can load the list of all leaderboards (which is GREAT for another part in my app); however, I would also like to be able to load one particular leaderboard. Here is the code I am using:

 @IBAction func showLeaderboard() {
    if savedSettings["difficulty"] == 0 {
        print("Easy")
        if savedSettings["gameLanguage"] == 0 {
            leaderboardID = "Colorific_English_High_Scores"
            print("english")
        } else if savedSettings["gameLanguage"] == 1 {
            leaderboardID = "Colorific_Spanish_High_Scores"
        } else {
            leaderboardID = "Colorific_French_High_Scores"
        }
    } else {
        if savedSettings["gameLanguage"] == 0 {
            leaderboardID = "Colorific_English_High_Scores_Hard"
        } else if savedSettings["gameLanguage"] == 1 {
            leaderboardID = "Colorific_Spanish_High_Scores_Hard"
        } else {
            leaderboardID = "Colorific_French_High_Scores_Hard"
        }
    }
    let gcVC: GKGameCenterViewController = GKGameCenterViewController()
    gcVC.leaderboardIdentifier = leaderboardID
    gcVC.gameCenterDelegate = self

    gcVC.viewState = GKGameCenterViewControllerState.Leaderboards

    self.presentViewController(gcVC, animated: true, completion: nil)
}

Unfortunately, updating the leaderboardIdentifier seems to have no effect. The list of all leaderboards always seems to show up. In fact... even changing the viewState to GKGameCenterViewControllerState.Achievements seems to have no effect, either! It always goes to that list of leaderboards :(

Thank you in advance for all of your help! :)


Solution

  • I know this was posted time ago, but i just got this same problem in my project.

    Your code has no problems, the issue is a bug with iOS9, there is a thread on the Apple's oficial forum with the other people's complaints: https://forums.developer.apple.com/thread/15997. They all have the same problem showing a specific leader board, however there is no official answer from Apple.

    I tried my game on a device with iOS8, and there was no problem showing a specific LeaderBoard. So right now, there is no much to do, till Apple fix the issue(It has been almost a year). I also suggest to use the Apple bug reporter, so they can notice the issue.

    Update for iOS10:

    iOS 10 have no problems showing specific leaderboard. Looks like it will remains as iOS9's problem.