Contents

GKTurnBasedMatchmakerViewController

An interface that allows a player to invite other players to a turn-based match and automatch to fill any empty slots.

Declaration

class GKTurnBasedMatchmakerViewController

Mentioned in

Overview

Before you create a GKTurnBasedMatchmakerViewController object, create a GKMatchRequest object and configure it according to the parameters of your game. Then, pass the match request to the init(matchRequest:) initializer to create the view controller.

Configure the view controller and set its delegate before you present it to the local player. The view controller allows the local player to choose other players and optionally fill empty slots using automatch. The interface also allows players to select an existing match, forfeit a match, or view a completed match.

Implement the GKTurnBasedMatchmakerViewControllerDelegate protocol to handle when a player selects players, cancels matchmaking, or encounters an error. Implement the turnBasedMatchmakerViewController(_:didFind:) delegate method to dismiss the view controller when the local player invites players.

Register as a listener of the GKLocalPlayerListener protocol and implement GKTurnBasedEventListener methods that handle other turn-based events. For example, implement the player(_:receivedTurnEventFor:didBecomeActive:) to update match data and present the gameplay interface for the local player to take their turn.

In iOS, you present and dismiss the view controller from another view controller in your game, using the methods provided by the UIViewController class. If you use SwiftUI, you can get the root view controller from the UIApplication object. In macOS, you use the GKDialogController class to present and dismiss the view controller.

Topics

Creating and Configuring the View Controller

Setting the Delegate

See Also

Turn-based games