0

我想让用户创建新匹配或加入使用创建新匹配创建的现有匹配,所有这些都以编程方式完成。我的问题是如何强制游戏中心只创建一个新匹配?苹果在他们的文档中提供的代码是:

-(IBAction)findProgrammaticMatch:(id)sender {
    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 2;
    request.maxPlayers = 2;
    [GKTurnBasedMatch findMatchForRequest:request withCompletionHandler:^(GKTurnBasedMatch *match,NSError *error) {
        if (match)
            // load gameplay
    }];
}

当且仅当没有现有匹配时,此代码才会创建一个新匹配,否则它将进行自动匹配。

4

1 回答 1

0

在 上使用playerAttributes属性GKMatchRequest

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;

if (wantsNewGame)
    request.playerAttribute = 0x0000FFFF;
else if (wantsJoin)
    request.playerAttribute = 0xFFFF0000;
else // don't care
    request.playerAttribute = 0xFFFFFFFF;

GKTurnBasedMatchmakerViewController *vc = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
于 2013-11-26T11:54:26.260 回答