Instance Method

findPlayersForHostedRequest:withCompletionHandler:

Initiates a request to find players for a hosted match.

Declaration

- (void)findPlayersForHostedRequest:(GKMatchRequest *)request withCompletionHandler:(void (^)(NSArray<GKPlayer *> *players, NSError *error))completionHandler;

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:

players

If matchmaking was successful, this parameter contains an array of GKPlayer 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

Matching Players

- cancel

Cancels a pending matchmaking request.

- cancelPendingInviteToPlayer:

Cancels a pending invitation to another player.

- findMatchForRequest:withCompletionHandler:

Initiates a request to find players for a peer-to-peer match.

- finishMatchmakingForMatch:

Informs Game Center that programmatic matchmaking has finished.

- queryActivityWithCompletionHandler:

Initiates a search for activity in all player groups.

- queryPlayerGroupActivity:withCompletionHandler:

Queries Game Center for the activity in a player group.