Mac Developer Library

Developer

GameKit Framework Reference GKGameCenterViewController Class Reference

Options
Deployment Target:

On This Page
Language:

GKGameCenterViewController

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. More...

Import Statement


import GameKit @import GameKit;

Availability


Available in OS X v10.9 and later.
  • viewState viewState Property

    The content displayed by the Game Center controller.

    Declaration

    Swift

    var viewState: GKGameCenterViewControllerState

    Objective-C

    @property(assign, atomic) GKGameCenterViewControllerState 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.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • The named leaderboard that is displayed by the view controller.

    Declaration

    Swift

    var leaderboardIdentifier: String!

    Objective-C

    @property(nonatomic, retain) NSString *leaderboardIdentifier

    Discussion

    The leaderboardIdentifier property must either be nil or it must match a leaderboard 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 leaderboardIdentifier property is automatically updated. For example, to preserve the player’s selections, you can read the leaderboardIdentifier property after the screen is dismissed, and set that value the next time you initialize the view controller.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.10 and later.

  • leaderboardCategory leaderboardCategory (OS X v10.10) Property

    The named leaderboard that is displayed by the view controller.

    Declaration

    Swift

    var leaderboardCategory: String!

    Objective-C

    @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.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

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

    Declaration

    Swift

    var leaderboardTimeScope: GKLeaderboardTimeScope

    Objective-C

    @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.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

  • Possible values for the viewState property.

    Declaration

    Swift

    enum GKGameCenterViewControllerState : Int { case Default case Leaderboards case Achievements case Challenges }

    Objective-C

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

    Constants

    • Default

      GKGameCenterViewControllerStateDefault

      Indicates that the view controller should present the default screen.

      Available in OS X v10.8 and later.

    • Leaderboards

      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.

    • Achievements

      GKGameCenterViewControllerStateAchievements

      Indicates that the view controller presents achievements content.

      Available in OS X v10.8 and later.

    • Challenges

      GKGameCenterViewControllerStateChallenges

      Indicates that the view controller presents challenges content.

      Available in OS X v10.8 and later.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.