Class

GKGameCenterViewController

A single user interface used to display achievements and leaderboards supported by Game Center.

Overview

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.

Topics

Configuring the Game Center View Controller’s Delegate

protocol GKGameCenterControllerDelegate

The delegate is called when the player dismisses the Game Center user interface.

Configuring the Game Center Controller’s Content

var viewState: GKGameCenterViewControllerState

The content displayed by the Game Center controller.

enum GKGameCenterViewControllerState

Possible values for the viewState property.

var leaderboardIdentifier: String?

The named leaderboard that is displayed by the view controller.

var leaderboardCategory: String?

The named leaderboard that is displayed by the view controller.

Deprecated
var leaderboardTimeScope: GKLeaderboardTimeScope

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

See Also

View Controllers

class GKDialogController

An object that provides the ability to present Game Center view controller classes in macOS.

protocol GKViewController

A protocol adopted by Game Center view controller classes.