msk
msk

Reputation: 527

GKTurnBasedMatch quitting out of turn

When a user quits "in turn" in a turn based match in an iOS app using GameKit, the delegate method -(void)turnBasedMatchmakerViewController: (GKTurnBasedMatchmakerViewController *)viewController playerQuitForMatch:(GKTurnBasedMatch *)match; is called on the GKTurnBasedMatchmakerViewController, in which according to the documentation, we should set the outcome for current player, and call participantQuitInTurnWithOutcome:nextParticipant:matchData:completionHandler:

However, I am not able to find any information regarding a player quiting out of turn. That is when it isn't my turn and I quit from the matchmaker viewcontroller. There doesn't seem to be any delegate method for that, and surprisingly, from debugging my app, I find out that turn is sent (even though it isn't my turn currently in the match).

Can anyone please explain the behavior and the correct way to handle out of turn quits.

Upvotes: 4

Views: 1792

Answers (3)

brimat
brimat

Reputation: 166

You can handle this scenario in

-(void)handleTurnEventForMatch:(GKTurnBasedMatch *)match

Loop through the participants and if the triggering player is the local player, and his outcome is "Quit", and he's not the current participant (which is handled in another place -turnBasedMatchmakerViewController:playerQuitForMatch:), then go ahead and quit the game out of turn.

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;
            }               
        }
    }
}

Upvotes: 2

thib_b
thib_b

Reputation: 129

There is actually a method to quit out of turn:

For a GKTurnBasedMatch it's called:

participantQuitOutOfTurnWithOutcome:withCompletionHandler:

You can call it in your GKTurnBaseMatchMakerViewControllerDelegate, when the turnBasedMatchmakerViewController:playerQuitForMatch: function is called.

Please see the official doc here

Upvotes: -1

Jan Ekholm
Jan Ekholm

Reputation: 124

You can check which is the current participant from the match and see if that is you. As for the sent traffic, doesn't Game Center need to inform all other players that you have quit?

Upvotes: 0

Related Questions