Sunday, 8 September 2013

Game Center Quickmatch: randomly matching opponents (GKTurnBasedMatch)

Game Center Quickmatch: randomly matching opponents (GKTurnBasedMatch)

I want there to be a "Quickmatch" mode in my turn-based game, where the
player gets automatically matched with the first player to become
available. I'm using my own custom UI. My code so far looks like this:
- (void)quickMatch {
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
[GKTurnBasedMatch findMatchForRequest:request
withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error) {
NSLog(@"MATCH: %@ %@ %@ %d",error,match,match.matchID,(int)match.status);
}];
This successfully creates a match, but the 2nd participant in the match
has a null ID (playerID:(null) status:Matching).
I thought that if I ran this same code on another instance, using a
different Game Center ID, then the two users would be matched against each
other... but that does not appear to be correct. Whenever I call the
GKTurnBasedMatch loadMatchesWithCompletionHandler function, I continue to
retrieve the same matches, each with only 1 valid participant (the local
player).
Of course, I could explicitly invite players during the GKMatchRequest,
but this is not the point: the quickmatch is supposed to pair the first
two users who press the "play" button.
How can I cause Game Center to automatically match these players against
each other?

No comments:

Post a Comment