Class

GKDialogController

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

Declaration

@interface GKDialogController : NSResponder

Overview

Instantiate and configure a Game Center view controller as you do for iOS. To present the view controller in macOS, instantiate a new GKDialogController object or use the Singleton object provided by the sharedDialogController class method. Set the parentWindow property of the dialog controller to the window that should display the view controller’s contents. Then, call the dialog controller’s presentViewController: method, passing in the view controller object to be presented. Later, when the view controller’s contents should be hidden, call the dialog controller’s dismiss: method. Listing 1 shows how to display a view controller that contains the scores for a single leaderboard.

Listing 1

Displaying the Game Center user interface in macOS

- (void) showLeaderboard: (NSString *) leaderboardID
{
    GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
    if (gameCenterController != nil)
    {
       gameCenterController.delegate = self;
       gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
       gameCenterController.leaderboardTimeScope = GKLeaderboardTimeScopeToday;
       gameCenterController.leaderboardCategory = leaderboardID;
       GKDialogController *sdc = [GKDialogController sharedDialogController];
       sdc.parentWindow = myWindow;
       [sdc presentViewController: gameCenterController];
    }
}

Listing 2 shows how to dismiss the delegate for macOS.

Listing 2

Responding when the player dismisses the Game Center content

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
{
    GKDialogController *sdc = [GKDialogController sharedDialogController];
    [sdc dismiss: self];
}

Topics

Accessing the Shared Dialog Controller

+ sharedDialogController

Retrieves the shared instance of the dialog controller.

Setting the Presentation Window

parentWindow

The window that view controllers presented by the dialog controller are displayed in.

Presenting and Dismissing the Dialog

- presentViewController:

Presents a view controller in the dialog controller’s window.

- dismiss:

Dismisses the currently displayed view controller.

Relationships

Inherits From

See Also

View Controllers

GKGameCenterViewController

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

GKViewController

The abstract base protocol adopted by Game Center view controller classes.