Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Game Center GameKit Programmatic Invite Matchmaking
    text
    copied!<p>I'm trying to implement a real-time multiplayer game with a custom UI (no GKMatchMakerViewController). I'm using startBrowsingForNearbyPlayersWithReachableHandler: ^(NSString *playerID, BOOL reachable) to find a local player, and then initiating a match request with the GKMatchmaker singleton (which I have already initiated).</p> <p>Here's where I'm having trouble. When I send a request, the completion handler fires almost immediately, without an error, and the match it returns has an expected player count of zero. Meanwhile, the other player definitely has not responded to the request</p> <p>Relevant Code:</p> <pre><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's 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]; } }]; } </code></pre> <p>I know from a previous question (<a href="https://stackoverflow.com/questions/14492171/ios-gamecenter-programmatic-matchmaking">iOS Gamecenter Programmatic Matchmaking</a>) that I need to include this:</p> <pre><code>- (void)matchForInvite:(GKInvite *)invite completionHandler:(void (^)(GKMatch *match, NSError *error))completionHandler </code></pre> <p>in the above code but I don't know where that should be included. I have tried it both the GKMatchRequest inviteeResponseHandler, and in the matchmaker finMatchForRequest:withCompletionHandler to no avail. The behavior that happens is that the matchmaker returns a match instantly (even before the invitee has been invited) and the matchRequest inviteeResponseHandler is never called even after the invitee taps the match invite.</p> <p>Can someone offer advice on this? Thank you.</p> <p>...Jim</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload