Class

GKDialogController

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

Declaration

class 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 shared() 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 present(_:) 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

class func shared() -> GKDialogController

Retrieves the shared instance of the dialog controller.

Setting the Presentation Window

var parentWindow: NSWindow?

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

Presenting and Dismissing the Dialog

func present(NSViewController & GKViewController) -> Bool

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

func dismiss(Any)

Dismisses the currently displayed view controller.

See Also

View Controllers

class GKGameCenterViewController

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

protocol GKViewController

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