How to open GameCenter in tvOS

How can I open the game center leaderboard in tvOS? I used this code for my iPhone games, "leaderboardIdentifier" is not available in tvOS.

I planned to use the same leaderboard on AppleTV (it will be the same game).

Thanks so much for your help, Stefan

@IBAction func handleGameCenter(sender: UIButton) { let gcViewController = GKGameCenterViewController() gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards gcViewController.leaderboardIdentifier = gamePrefix + "Leaderboard" gcViewController.gameCenterDelegate = self // Show leaderboard self.presentViewController(gcViewController, animated: true, completion: nil) } func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController) { gameCenterViewController.dismissViewControllerAnimated(true, completion: nil) } 
+6
source share
3 answers

I also had a problem with the "No data" screen, but finally it was resolved. This helped me open the gamecenter leaderboard on tvOS:

  • open Assets.xcassets (the same file where you installed the application icon / launch screen)
  • right click on the panel using appicon / launchsreen and select Game Center β†’ New Apple TV Leaderboard
  • add graphics for the new leaderboard
  • while the leaderboard is selected in the asset file in the right sidebar, find the ID field and place the identifier of your leaderboard.
  • use this code to open the leaderboard:

     GKGameCenterViewController *gcViewController = [[GKGameCenterViewController alloc] init]; gcViewController.gameCenterDelegate = self; [self presentViewController:gcViewController animated:YES completion:nil]; 
+13
source

It just works:

 GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init]; if (gameCenterController != nil) { gameCenterController.gameCenterDelegate = self; [self presentViewController: gameCenterController animated: YES completion:nil]; } 
+1
source

. viewState and leaderboardIdentifier are not available on tvOS, so you can open the GC controller with this code, but the page will say β€œNo data”.

+1
source

All Articles