The GKGameCenterViewController class aggregates many common Game Center features into a single user interface. It replaces GKAchievementViewController and GKLeaderboardViewController as the preferred way to show Game Center content in your game.


To display the Game Center screen, initialize a new GKGameCenterViewController object and set its delegate. Optionally, you can choose to configure the view controller further to specify which content is initially displayed. Then present the view controller. Your delegate is called when the user dismisses the screen. Listing 1 shows how to present a new GKGameCenterViewController and display the scores for a specific leaderboard.

Listing 1

Displaying the leaderboard page of the Game Center user interface

- (void) showLeaderboard: (NSString*) leaderboardID
    GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
    if (gameCenterController != nil)
       gameCenterController.gameCenterDelegate = self;
       gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
       gameCenterController.leaderboardTimeScope = GKLeaderboardTimeScopeToday;
       gameCenterController.leaderboardCategory = leaderboardID;
       [self presentViewController: gameCenterController animated: YES completion:nil];

Your game should pause other activities before presenting the Game Center user interface.


Configuring the Game Center View Controller’s Delegate

Configuring the Game Center Controller’s Content

var viewState: GKGameCenterViewControllerState

The content displayed by the Game Center controller.

var leaderboardIdentifier: String?

The named leaderboard that is displayed by the view controller.

var leaderboardTimeScope: GKLeaderboardTimeScope

A time filter used to restrict which scores are displayed to the player.



Possible values for the viewState property.