简体   繁体   中英

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

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!

好的,现在沙箱Game Center服务器已备份,我能够通过将playersToInvite属性设置为nil或不全部设置来确认自动匹配有效。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM