GKMatchmakerViewController
An interface that allows a player to invite other players to a real-time game and automatch to fill any empty slots.
Declaration
class GKMatchmakerViewControllerMentioned in
Overview
Before you create a GKMatchmakerViewController 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. If you add the Group Activities capability to your Xcode project, the player can invite others using SharePlay. See Configuring Group Activities.
Implement the GKLocalPlayerListener and GKMatchmakerViewControllerDelegate protocols to handle when players send and accept invitations. Implement the player(_:didAccept:) delegate method to present a GKMatchmakerViewController object, which you create using the init(invite:) initializer, to the player who accepts an invitation. Then, implement the matchmakerViewController(_:didFind:) delegate method to dismiss the view controller and start the game when all players accept their invitations.
In iOS, you present and dismiss the view controller from another view controller in your game, using the methods from the UIViewController class. If you use SwiftUI, you can get the root view controller from the UIApplication object.
let rootViewController = UIApplication.shared.windows.first!.rootViewControllerFor visionOS games, the view controller appears anchored to the window, scene, or view relative to where you present the view controller. For immersive games, set the parent window to a separate window group than the immersive space window group.
For macOS games, use the GKDialogController class to present and dismiss the view controller.
For the complete matchmaking flow with code fragments, see Finding multiple players for a game.
Topics
Creating and configuring the view controller
init(matchRequest:)init(invite:)matchRequestcanStartWithMinimumPlayersmatchmakingModeGKMatchmakingMode