Instance Method

findPlayers(forHostedMatchRequest:withCompletionHandler:)

Initiates a request to find players for a hosted match.

Declaration

func findPlayers(forHostedMatchRequest request: GKMatchRequest, withCompletionHandler completionHandler: (([String]?, Error?) -> Void)? = nil)

Parameters

request

The configuration for the desired match.

completionHandler

A block to be called when the match has been created. This block receives the following parameters:

playerIDs

If matchmaking was successful, this parameter contains an array of NSString objects containing the players to connect into the match. Otherwise, this parameter is nil.

error

If matchmaking was successful, this parameter contains nil. Otherwise, this parameter holds an error object that describes the error that occurred.

Discussion

When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. The completion handler is always called on the main thread. When your completion handler is called, your game should connect those players to your own server.

On iOS 6, if the match request’s playersToInvite property is non-NIL, Game Center sends invitations only out to the players listed in the property. If the playersToInvite property is NIL, then it searches for any waiting players that match the request. Prior to iOS 6, the match request’s playersToInvite property is ignored and this method only searches for available players.

See Also

Deprecated Methods and Properties

func cancelInvite(toPlayer: String)

Cancels a pending invitation to another player.

Deprecated
var inviteHandler: ((GKInvite, [Any]?) -> Void)?

A block to be called when an invitation to join a match is accepted by the local player.

Deprecated
func startBrowsingForNearbyPlayers(reachableHandler: ((String, Bool) -> Void)?)

Enables the matchmaking process to find nearby players through Bluetooth or WiFi (same subnet only).

Deprecated

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software