Contents

GKDialogController

An object that provides the ability to present the dashboard in macOS games.

Declaration

class GKDialogController

Overview

For macOS games, use a GKDialogController object to present the dashboard from which players can browse and manage their Game Center data.

Initialize a new GKGameCenterViewController object, as you would for an iOS game, specifying the state and setting its delegate. Then get the singleton dialog controller using the shared() class method, or initialize a new GKDialogController object.

To present the dashboard, set the parentWindow property to the window that should display the dashboard and then call the present(_:) method, passing the GKGameCenterViewController object.

func presentAchievement() {
    let viewController = GKGameCenterViewController(achievementID: "101")
    viewController.gameCenterDelegate = self
    
    let dialogController = GKDialogController.shared()
    dialogController.parentWindow = NSApplication.shared.mainWindow
    dialogController.present(viewController)
}

When the player closes the dashboard, GameKit calls the gameCenterViewControllerDidFinish(_:) delegate method. Implement this method to dismiss the shared dialog controller using the dismiss(_:) method.

func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) {
    // Dismiss the view controller.
    let dialogController = GKDialogController.shared()
    dialogController.dismiss(self)
}

Topics

Accessing the Shared Dialog Controller

Setting the Presentation Window

Presenting and Dismissing the Dialog

See Also

Game Center interfaces