The Game Center turn-based matchmaking interface allows a user to create a match with a number of players and fill some of those places with invites to friends and leave the others for auto-matching.
I am creating our own in-game match creation interface which works fine, so far, except when it comes to creating a match with both invited and auto-match players.
GKMatchmaker has the addPlayersToMatch method where I believe you can add auto-match players once the match exists, but GKTurnBasedMatch has no equivalent method.
The following is the code I am using, which works just fine. If anyone knows how to add a number of auto-match players it would be much appreciated!
- (GKMatchRequest *) buildMatchRequestWithFriends: (NSArray *) friendsList NumberOfPlayers: (NSInteger) numberOfPlayers
{
NSLog(@"TurnByTurnHelper.buildMatchRequestWithFriends");
GKMatchRequest *request = [[GKMatchRequest alloc] init];
NSArray *playersToInvite = [NSArray arrayWithArray:friendsList];
request.playersToInvite = playersToInvite;
request.defaultNumberOfPlayers = numberOfPlayers + 1;
return request;
}
- (void) requestMatchWithFriends:(NSArray *) friendsList NumberOfPlayers: (NSInteger) numberOfPlayers{
if (!_delegate)
{
NSLog(@"Error: Expected but did not find delegate");
return;
}
GKMatchRequest *request = [self buildMatchRequestWithFriends:friendsList NumberOfPlayers: numberOfPlayers];
[GKTurnBasedMatch findMatchForRequest: request withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
{
if (match){
NSLog(@"findMatchForRequest: Success!");
// Add match to matches
} else {
NSLog(@"error: %@", error);
}
}];
}