iOS Development: How do I auto match players in Game Center?

I have a “Play Now” button in my app that allows players to be auto-matched with other random players. Maybe I’m missing this somewhere in the docs, but how do I write the code to auto match players?

The Game Center sandbox server has been messed up the last few days, so I’m having a hard time trying different things since I have to guess because the Game Kit docs aren’t exactly clear on how to do this. Currently, I have code setup (but untested) to create a match with a friend…

  • Offline Game Center iOS Achievements
  • iOS Game Center: Scores not showing on leaderboard in sandbox
  • IOS Game Center GKLocalPlayerListener
  • handleTurnEventForMatch:didBecomeActive: callbacks only arriving some of the time
  • PAN with Linux, iOS, Bluetooth, Bonjour, GameKit — Possible?
  • Calling report achievements performance?
  • NSArray *playerList = [NSArray arrayWithObject:pid];
    GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
    request.minPlayers = 2;
    request.maxPlayers = 4;
    request.playersToInvite = playerList;
    
    [[self waitingIndicator] startAnimating];
    
    [[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
        if (error)
        {
            //handle error
        }
    
        else if (match != nil)
        {
            self.myMatch = match;
    
            //start match code
        }
    }];
    

    But how do I auto match two random people looking for a game? My guess, since the docs don’t say it, or I’m missing it, is that in order to create an auto match, I simply set the playersToInvite property of the match object to nil? If not, how do I create an auto match?

    One other question, while we’re on the topic, the Game Kit docs site a few common matchmaking scenarios, one of them being…

    A player can also create a network
    match using the Game Center
    application. When they invite a friend
    into a multiplayer game, your
    application is launched on both
    devices, and each copy of your
    application receives an invitation to
    join the game.

    But I can’t figure out how to do this in the Game Center app for testing purposes. How does a user create a network match using the Game Center app? I don’t see any buttons for that anywhere in the Game Center app.

    Thanks in advance for your wisdom!

    Solutions Collect From Internet About “iOS Development: How do I auto match players in Game Center?”

    Ok, now that the sandbox Game Center server is back up, I was able to confirm that auto-matching works by setting the playersToInvite property to nil, or not setting it all.