I'm working on a turn based iOS game using game center and right now I have my test account participating in six games in Game Center, but every time I try to quit one by swiping on it (which should really end the game because my test account is the only one in it) it removes the game from the table for a split second and then replaces it immediately and doesn't quit.
Here is my playerQuitForMatch function:
// Handle players leaving the match in and out of turn.
- (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController
playerQuitForMatch:(GKTurnBasedMatch *)match
{
// If the player was the current participant, remove them from the next participants array.
if ([match.currentParticipant.playerID isEqualToString:GKLocalPlayer.localPlayer.playerID])
{
NSMutableArray* nextParticipants = [NSMutableArray arrayWithArray:[match participants]];
[nextParticipants removeObjectIdenticalTo:[match currentParticipant]];
// If they were the last player, end the match because it is empty.
if ([nextParticipants count] == 0)
{
[match endMatchInTurnWithMatchData:match.matchData completionHandler:nil];
}
// Otherwise, remove them from the match and pass priority.
else
{
[match participantQuitInTurnWithOutcome:GKTurnBasedMatchOutcomeQuit
nextParticipants:nextParticipants
turnTimeout:0.0f
matchData:match.matchData
completionHandler:nil];
}
}
// If they weren't the current participant, just remove them from the match.
else
{
NSMutableArray* nextParticipants = [NSMutableArray arrayWithArray:[match participants]];
[nextParticipants removeObjectIdenticalTo:[match currentParticipant]];
// The player can't be the last person in the game if they aren't the active player.
[match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:nil];
}
NSLog(@"playerquitforMatch, %@, %@", match, match.currentParticipant);
}
And here's the console output:
2013-05-04 13:16:13.180 XYZ Mobile[7799:c07] Authenticating local user...
2013-05-04 13:16:13.587 XYZ Mobile[7799:c07] Authentication changed: player authenticated.
May 4 13:16:13 folsom-wireless-153.dynamic2.rpi.edu XYZ Mobile[7799] <Info>: 13:16:13.597120 com.apple.AVConference: GKSConnSettings: set server: {
"gk-cdx" = "17.173.254.218:4398";
"gk-commnat-cohort" = "17.173.254.220:16386";
"gk-commnat-main0" = "17.173.254.219:16384";
"gk-commnat-main1" = "17.173.254.219:16385";
}
2013-05-04 13:16:21.380 XYZ Mobile[7799:c07] 101
2013-05-04 13:16:58.150 XYZ Mobile[7799:c07] New Game Button Pressed
2013-05-04 13:17:00.146 XYZ Mobile[7799:c07] playerquitforMatch, <GKTurnBasedMatch 0x949ece0 id:0a8b8246-1872-410e-b9ae-819a9a00d4ff status:Open message:(null) taken:(null) created:2013-04-24 23:32:35 +0000
current:<GKTurnBasedParticipant 0x949ad50 - id:(null) status:Matching outcome:None lastTurn:(null)>
participants:
<GKTurnBasedParticipant 0x949ad40 - id:G:1759434517 (local player) status:Done outcome:Quit lastTurn:(null)>
<GKTurnBasedParticipant 0x949ad50 - id:(null) status:Matching outcome:None lastTurn:(null)>
<GKTurnBasedParticipant 0x949f2b0 - id:(null) status:Matching outcome:None lastTurn:(null)>
<GKTurnBasedParticipant 0x949f2c0 - id:(null) status:Matching outcome:None lastTurn:(null)>
<GKTurnBasedParticipant 0x949f650 - id:(null) status:Matching outcome:None lastTurn:(null)>
<GKTurnBasedParticipant 0x949f660 - id:(null) status:Matching outcome:None lastTurn:(null)>
<GKTurnBasedParticipant 0x949bc20 - id:(null) status:Matching outcome:None lastTurn:(null)>
<GKTurnBasedParticipant 0x949bc30 - id:(null) status:Matching outcome:None lastTurn:(null)>
>, <GKTurnBasedParticipant 0x949ad50 - id:(null) status:Matching outcome:None lastTurn:(null)>
2013-05-04 13:17:08.523 XYZ Mobile[7799:c07] has cancelled