iOS Gamecenter Programmatic Matchmaking

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).

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.

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
        [self.delegate updateUIForPlayer: playerID accepted: (response ==
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];


Figured it out! 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.

Need Your Help

Project is growing ang growing, Xcode slowing down

xcode project

My projects is growing. It includes about 16 thousands .m4a (sound) files, because it's the App helping to learn languages with examples, but only few classes and files containing code.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.