Can';t在iPhone/IOS 5上使用[GKMatchmaker addPlayersToMatch]添加其他玩家

Can';t在iPhone/IOS 5上使用[GKMatchmaker addPlayersToMatch]添加其他玩家,iphone,ios,center,Iphone,Ios,Center,我有一个游戏中心应用程序。我成功连接了两个客户端并可以发送消息等。我现在正尝试添加一个第三/第四个客户端,使用[GKMatchmaker addPlayersToMatch]像这样 - (void) findAdditionalPlayer { GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; request.minPlayers = 2; // minPlayers = 3 doesn

我有一个游戏中心应用程序。我成功连接了两个客户端并可以发送消息等。我现在正尝试添加一个第三/第四个客户端,使用
[GKMatchmaker addPlayersToMatch]
像这样

- (void) findAdditionalPlayer
{
    GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
    request.minPlayers = 2;  // minPlayers = 3 doesn't work either
    request.maxPlayers = 4;

    [[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:request completionHandler:^(NSError *error)
    {
        if (error)
        {
            // Process the error.
            NSLog(@"Could not find additional player - %@", [error localizedDescription]);
        }
        else
        {
            NSLog(@"Find additional player expecting = %d", match.expectedPlayerCount);
        }
    }];
}
如果一个客户端(投票服务器)调用
findAdditionalPlayer
,我将无法连接(另一个客户端正在使用
GKMatchmakerViewController
)。奇怪的是,如果两个连接的客户端都调用了
findAddtionalPlayer
,那么我的完成块将执行
(match.expectedPlayerCount==2)
,但我的第三个客户端从未连接

应该只有一个游戏客户端调用上面的函数吗?文档并没有具体说明


有没有人举过使用addPlayersToMatch的例子?

根据我的经验,对于2人游戏,addPlayersToMatch应该由两名玩家执行,以便他们重新连接到游戏(并通过游戏中心来回通信)

如果您的两个客户端都调用findAdditionalPlayer,则可以连接,因为它们都调用AddPlayerToMatch

如果您已经有一个有两名玩家(比如a和B)的游戏,并且您想要第三名玩家(比如C)加入,您必须:

在播放器A(邀请C)中:

在播放器B(邀请C)中:

在玩家C中(邀请A和B):

因此,重新加入或向比赛中添加新球员的机制似乎是:

  • 当玩家检测到远程玩家已断开连接(或添加了全新玩家)时,创建一个新的比赛请求对象,在此新比赛请求的PlayerToInvite数组中仅包含断开连接/新玩家的id,并使用它执行AddPlayerToMatch
  • 当断开连接的玩家恢复时,创建一个新的比赛请求对象,在其比赛请求的PlayerToInvite数组中包含所有远程玩家的ID(您可能需要提前将其存储在数组中,或者从GKMatch的PlayerID属性中获取),并用它执行AddPlayerToMatch
  • 换句话说,每个现有玩家都会将新玩家添加到其比赛对象中,而新玩家会将所有现有玩家添加到其比赛对象中

    对于4人游戏(玩家a、B、C和D,其中玩家D是最新添加的):
    玩家A、B和C各自使用一个match request对象执行AddPlayerToMatch调用,该对象的playerToInvite仅由D的playerID组成。当玩家D使用其playerToInvite数组包含a、B和C的玩家ID的match request对象执行其AddPlayerToMatch调用时。

    根据我的经验,对于一个2人游戏,两个玩家都应该执行AddPlayerToMatch,以便重新连接到游戏(并通过游戏中心来回通信)

    如果您的两个客户端都调用findAdditionalPlayer,则可以连接,因为它们都调用AddPlayerToMatch

    如果您已经有一个有两名玩家(比如a和B)的游戏,并且您想要第三名玩家(比如C)加入,您必须:

    在播放器A(邀请C)中:

    在播放器B(邀请C)中:

    在玩家C中(邀请A和B):

    因此,重新加入或向比赛中添加新球员的机制似乎是:

  • 当玩家检测到远程玩家已断开连接(或添加了全新玩家)时,创建一个新的比赛请求对象,在此新比赛请求的PlayerToInvite数组中仅包含断开连接/新玩家的id,并使用它执行AddPlayerToMatch
  • 当断开连接的玩家恢复时,创建一个新的比赛请求对象,在其比赛请求的PlayerToInvite数组中包含所有远程玩家的ID(您可能需要提前将其存储在数组中,或者从GKMatch的PlayerID属性中获取),并用它执行AddPlayerToMatch
  • 换句话说,每个现有玩家都会将新玩家添加到其比赛对象中,而新玩家会将所有现有玩家添加到其比赛对象中

    对于4人游戏(玩家a、B、C和D,其中玩家D是最新添加的):
    玩家A、B和C各自使用一个match request对象执行AddPlayerToMatch调用,该对象的playerToInvite仅由D的playerID组成。当播放器D使用其playerToInvite数组包含的match request对象执行AddPlayerToMatch调用时,B以及C的玩家ID。

    我遇到了4个玩家在玩的问题。如果1个玩家断开连接,那么其他3个玩家也断开连接。是的。如何克服这种情况。我遇到了4个玩家在玩的问题。如果1个玩家断开连接,那么其他3个玩家也断开连接。是的。如何克服这种情况。
    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 3;
    request.maxPlayers = 4;
    request.playersToInvite = [NSArray arrayWithObject:playerC_id];
    [[GKMatchmaker sharedMatchmaker] addPlayersToMatch:myMatch matchRequest:request completionHandler:nil];
    
    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 3;
    request.maxPlayers = 4;
    request.playersToInvite = [NSArray arrayWithObject:playerC_id];
    [[GKMatchmaker sharedMatchmaker] addPlayersToMatch:myMatch matchRequest:request completionHandler:nil];
    
    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 3;
    request.maxPlayers = 4;
    request.playersToInvite = [NSArray arrayWithObjects:playerA_id, playerB_id, nil];
    [[GKMatchmaker sharedMatchmaker] addPlayersToMatch:myMatch matchRequest:request completionHandler:nil];