I am developing a turn-based game with two Game Center players, and I want to allow auto-matching.
I've read that, for an invitation to be actually sent out to a player, the inviting player must end his/her turn. This means calling this method:
- (void)endTurnWithNextParticipants:(NSArray *)nextParticipants turnTimeout:(NSTimeInterval)timeout matchData:(NSData *)matchData completionHandler:(void (^)(NSError *error))completionHandler
Now, what I don't understand is the meaning of the "nextParticipants" array in case the match is started in auto-match mode, which, as I read, is done by setting the participants to nil, e.g.:
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = nil;
request.inviteMessage = @"Let’s play";
[GKTurnBasedMatch findMatchForRequest: request
withCompletionHandler: ^(GKTurnBasedMatch *match,
NSError *error) {
NSLog(@"%@", match);
}];
If the array is nil, and I don't know who's going to join the match, how can I possibly pass the turn to the next player? If I use nil in the nextParticipants argument, of course I get an 'invalid list of nextParticipants' error.
Apple's doc seems to be silent about this.
So, what I also don't understand is how auto-matching actually works. Is it going to match any two players who have started a new match with auto-match, unconditionally? Can't I somehow select what kind of matches I want to be auto-matched with? (suppose, e.g., the game allows several difficulty levels, and I don't want to be auto-matched with someone playing at a lower level).
EDIT (as per xcodegirl's comment):
To address this last point, it suffices to extend the above code by adding something that encodes the desired kind of match in the playerGroup property of the request:
request.playerGroup = [Utils myEncodingAsNSUIntegerOfGameTypeGivenSomeParameters:...];
The bad thing, though, is that the playerGroup does not seem to be an available property of GKTurnBasedMatch. So, if you are listing your matches, including the pending auto-matches, and want to display information regarding the kind of game you want to play, you should store this info in some other way.