findPlayers(forHostedMatchRequest:withCompletionHandler:)
Initiates a request to find players for a hosted match.
Declaration
func findPlayers(forHostedMatchRequest request: GKMatchRequest, withCompletionHandler completionHandler: (@Sendable ([String]?, (any Error)?) -> Void)? = nil)func findPlayers(forHostedMatchRequest request: GKMatchRequest) async throws -> [String]Parameters
- request:
The configuration for the desired match.
- completionHandler:
A block to call when GameKit creates the match. This block receives the following parameters:
- playerIDs
If matchmaking was successful, this parameter contains an array of
NSStringobjects containing the players to connect into the match. Otherwise, this parameter isnil.- error
If matchmaking was successful, this parameter contains
nil. Otherwise, this parameter holds an error object that describes the error that occurred.
Discussion
When GameKit calls this completion handler, your game needs to connect those players to your own server.
On iOS 6, if the match request’s playersToInvite property is non-NIL, Game Center only sends invitations out to the players listed in the property. If the playersToInvite property is NIL, Game Center then searches for any waiting players that match the request. Prior to iOS 6, GameKit ignores the match request’s playersToInvite property and this method only searches for available players.