GKGameCenterViewController Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/GameKit.framework
Availability
Available in OS X v10.9 and later.
Companion guide
Declared in
GKGameCenterViewController.h

Overview

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.

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

Tasks

Configuring the Game Center View Controller’s Delegate

Configuring the Game Center Controller’s Content

Properties

gameCenterDelegate

The view controller’s delegate.

@property(nonatomic, assign) id<GKGameCenterControllerDelegate> gameCenterDelegate
Discussion

Before displaying the view controller, your game must set a delegate.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKGameCenterViewController.h

leaderboardCategory

The named leaderboard that is displayed by the view controller.

@property(nonatomic, retain) NSString *leaderboardCategory
Discussion

The category property must either be nil or it must match a category identifier you defined when you created your leaderboards on iTunes Connect. If nil, the view displays scores for the aggregate leaderboard. Default is nil.

When the leaderboard is presented, the value of this property determines which leaderboard content is displayed to the player. As the player changes which leaderboard content they view, the leaderboardCategory property is automatically updated. For example, to preserve the player’s selections, you can read the leaderboardCategory property after the screen is dismissed, and set that value the next time you initialize the view controller.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKGameCenterViewController.h

leaderboardTimeScope

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

@property(nonatomic, assign) GKLeaderboardTimeScope leaderboardTimeScope
Discussion

This property determines which tab view of the scores screen is displayed to the player. The default value is GKLeaderboardTimeScopeAllTime, which shows the best score each player has earned. For more information on time scopes, see GKLeaderboard Class Reference.

When the leaderboard is presented, the value of this property determines the initial tab that is displayed to the player. As the player changes which tab they view, the leaderboardTimeScope property is automatically updated. For example, to preserve the player’s selections, you can read the leaderboardTimeScope property after the screen is dismissed, and set that value the next time you initialize the view controller.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKGameCenterViewController.h

viewState

The content displayed by the Game Center controller.

@property(nonatomic, assign) GKGameCenterControllerViewState viewState
Discussion

See “Game Center Controller View State” for possible values. When you first present the Game Center view controller, the content displayed by the view controller is determined by this property. If the player navigates to different content, the view state is automatically updated. For example, to preserve the player’s selections, you can read the viewState property after the screen is dismissed, and set that value the next time you initialize the view controller.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKGameCenterViewController.h

Constants

Game Center Controller View State

Possible values for the viewState property.

typedef enum /*: NSInteger */ {
   GKGameCenterViewControllerStateDefault = -1,
   GKGameCenterViewControllerStateLeaderboards ,
   GKGameCenterViewControllerStateAchievements,
   GKGameCenterViewControllerStateChallenges,
} GKGameCenterViewControllerState;
Constants
GKGameCenterViewControllerStateDefault

Indicates that the view controller should present the default screen.

Available in OS X v10.8 and later.

Declared in GKGameCenterViewController.h.

GKGameCenterViewControllerStateLeaderboards

Indicates that the view controller presents leaderboard content. The leaderboardCategory and leaderboardTimeScope properties affect the appearance of this view state.

Available in OS X v10.8 and later.

Declared in GKGameCenterViewController.h.

GKGameCenterViewControllerStateAchievements

Indicates that the view controller presents achievements content.

Available in OS X v10.8 and later.

Declared in GKGameCenterViewController.h.

GKGameCenterViewControllerStateChallenges

Indicates that the view controller presents challenges content.

Available in OS X v10.8 and later.

Declared in GKGameCenterViewController.h.