Class

GKTurnBasedMatchmakerViewController

A user interface that allows players to manage the turn-based matches that they are participating in.

Overview

To show a turn-based matching user interface, first allocate and initialize a GKMatchRequest object that describes the desired match. Then, use the match request to initialize a new GKTurnBasedMatchmakerViewController object. Set the view controller’s delegate, present the view controller, and wait for the delegate to be called. The view controller’s delegate is notified when the matchmaking process is completed or canceled. Once the delegate is called, dismiss the view controller.

In iOS, you present and dismiss the view controller from another view controller in your game, using the methods provided by the UIViewController class. In macOS, you use the GKDialogController class to present and dismiss the view controller. Listing 1 shows a typical implementation.

Listing 1

Displaying the standard interface to join a turn-based match

- (IBAction)joinChessMatch: (id) sender
{
    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 2;
    request.maxPlayers = 2;
 
    GKTurnBasedMatchmakerViewController *mmvc = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
    mmvc.turnBasedMatchmakerDelegate = self;
 
    [self presentViewController:mmvc animated:YES completion:nil];
}

Topics

Displaying a UI For Turn-Based Matches

init(matchRequest: GKMatchRequest)

Initializes a new matchmaker view controller.

var showExistingMatches: Bool

A Boolean value that determines whether the view controller shows existing matches.

protocol GKTurnBasedMatchmakerViewControllerDelegate

Your game implements the GKTurnBasedMatchmakerViewControllerDelegate protocol on an object to respond to events generated by a GKTurnBasedMatchmakerViewController object.

See Also

Player Invitations

class GKMatchmaker

An object that programmatically creates matches with other players and receives match invitations sent by other players.

class GKMatchmakerViewController

A user interface for inviting friends to a match or for allowing Game Center to fill the remaining players needed for a match.

class GKInvite

A matchmaking invitation sent by another player to the local player.