IOS Gamecenter Programmatic Matchmaking

I am trying to implement a real-time multiplayer game with a user interface (no GKMatchMakerViewController ). I use startBrowsingForNearbyPlayersWithReachableHandler: ^(NSString *playerID, BOOL reachable) to find the local player and then initiates a match request with the GKMatchmaker syntax (which I already started).

Here where I have problems. When I submit the request, the completion handler starts almost immediately, without error, and the returned match has the expected number of players equal to zero. Meanwhile, the other player definitely did not respond to the request.

Relevant Code:

 - (void) findMatch { GKMatchRequest *request = [[GKMatchRequest alloc] init]; request.minPlayers = NUM_PLAYERS_PER_MATCH; //2 request.maxPlayers = NUM_PLAYERS_PER_MATCH; //2 if (nil != self.playersToInvite) { // we always successfully get in this if-statement request.playersToInvite = self.playersToInvite; request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse response) { [self.delegate updateUIForPlayer: playerID accepted: (response == GKInviteeResponseAccepted)]; }; } request.inviteMessage = @"Let Play!"; [self.matchmaker findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) { if (error) { // Print the error NSLog(@"%@", error.localizedDescription); } else if (match != nil) { self.currentMatch = match; self.currentMatch.delegate = self; // All players are connected if (match.expectedPlayerCount == 0) { // start match [self startMatch]; } [self stopLookingForPlayers]; } }]; } 
+1
source share
1 answer

I thought! I needed to call - (void)matchForInvite:(GKInvite *)invite completionHandler:(void (^)(GKMatch *match, NSError *error))completionHandler in my invitation handler so that both players have the same match data.

+1
source

All Articles