Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios GKTurnBasedMatch不按顺序退出_Ios_Gamekit - Fatal编程技术网

Ios GKTurnBasedMatch不按顺序退出

Ios GKTurnBasedMatch不按顺序退出,ios,gamekit,Ios,Gamekit,当用户使用GameKit在iOS应用程序中的基于回合的比赛中“依次”退出时,委托方法-(void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController*)viewController playerQuitForMatch:(GKTurnBasedMatch*)match在GKTurnBasedMatchmakerViewController上调用,根据文档,我们应该在其中为当前玩家设置结果,并调用Partic

当用户使用GameKit在iOS应用程序中的基于回合的比赛中“依次”退出时,委托方法
-(void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController*)viewController playerQuitForMatch:(GKTurnBasedMatch*)match
在GKTurnBasedMatchmakerViewController上调用,根据文档,我们应该在其中为当前玩家设置结果,并调用
ParticipantQuitInturnWithOutput:nextParticipant:matchData:completionHandler

然而,我找不到任何关于球员不按顺序退出的信息。那时候轮到我了,我退出了matchmaker viewcontroller。似乎没有任何委托方法可以做到这一点,令人惊讶的是,通过调试我的应用程序,我发现该回合已被发送(尽管目前比赛中没有轮到我)


有谁能解释一下这种行为以及处理不按顺序退出的正确方法吗

你可以检查比赛中的当前参与者是谁,看看是不是你。至于发送的流量,游戏中心不需要通知所有其他玩家您已经退出吗?

实际上有一种方法可以不按顺序退出:

对于GKTurnBasedMatch,它被称为:

participantQuitOutOfTurnWithOutcome:withCompletionHandler:

调用turnBasedMatchmakerViewController:playerQuitForMatch:函数时,可以在GkturnBaseMatchMakerViewController中调用它


请参阅官方文档

您可以在

-(void)handleTurnEventForMatch:(GKTurnBasedMatch *)match

循环遍历参与者,如果触发玩家是本地玩家,其结果是“退出”,并且他不是当前参与者(在另一个地方处理-turnBasedMatchmakerViewController:playerQuitForMatch:),则继续并依次退出游戏

for (int i = 0; i < [match.participants count]; i++) 
{            
    GKTurnBasedParticipant *p = [match.participants objectAtIndex:i];

    if ([p.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID])
    {
        // Found player

        if (p.matchOutcome == GKTurnBasedMatchOutcomeQuit)
        {
            // Player Quit... ignore current participants and end out of turn only for the other player
            if (![match.currentParticipant.playerID isEqualToString:p.playerID])
            {
                // not the current participant and he quit
                [match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:nil];
                 break;
            }               
        }
    }
}
for(int i=0;i<[match.participants count];i++)
{            
GKTurnBasedParticipant*p=[match.participants objectAtIndex:i];
if([p.playerID isEqualToString:[GKLocalPlayer].playerID])
{
//找到玩家
如果(p.matchOutput==GKTurnBasedMatchOutcomeQuit)
{
//玩家退出…忽略当前参与者,仅对其他玩家结束轮换
如果(![match.currentParticipant.playerID isEqualToString:p.playerID])
{
//不是当前参与者,他退出了
[match Participant Quitout of Turnwith Output:GKTurnBasedMatch Outcome Quit with CompletionHandler:nil];
打破
}               
}
}
}

turnBasedMatchmakerViewController:playerQuitForMatch:在玩家不按顺序退出时不被调用,因此这不起作用。