ios - Proper GKTurnBasedMatch End Of Match When participantQuitOutOfTurnWithOutcome -
ios - Proper GKTurnBasedMatch End Of Match When participantQuitOutOfTurnWithOutcome -
in turn based match, unable cleanly end match when out of turn player quits match. believe preventing me starting rematch.
here have observed. when examine completed game status of game gkturnbasedmatchmakerviewcontroller of player 1's device, shows match outcome of player 1 quit , match outcome of player 2 "this player's turn". however, if examine completed game status of game gkturnbasedmatchmakerviewcontroller of player 2's device, shows match outcome of player 1 quit , match outcome of player 2 "won". but, if click on "view game" gkturnbasedmatchmakerviewcontroller within player 1 device, match outcome switches "won" player 2. how end game player 2 has match outcome of "won" perspective of player 1?
in scenario, player 1 starts match , takes turn. player 2 starts turn. during time, player 1 quits match. code sequence follows:
player 1:
[currentmatch participantquitoutofturnwithoutcome:gkturnbasedmatchoutcomequit withcompletionhandler:nil];
player 2 - after receiving phone call handleturneventformatch:didbecomeactive:
// each participant, set matchoutcome relative local player has won. (gkturnbasedparticipant *part in [currentmatch.participants) { if ([part.playerid isequaltostring:[gklocalplayer localplayer].playerid]) { part.matchoutcome = gkturnbasedmatchoutcomewon; } else { part.matchoutcome = gkturnbasedmatchoutcomequit; } } [currentmatch endmatchinturnwithmatchdata: info completionhandler: ^(nserror *error) { if (error) { nslog(@"%@", error); } else { nslog(@"after win: match ended successfully"); }];
player 1 receives prompt asking whether want rematch. if user responds affirmatively, next sent:
[currentmatch rematchwithcompletionhandler:^(gkturnbasedmatch *rematch, nserror *error) { if (error) { nslog(@"in rematchwithcompletionhandler. error creating rematch: %@", error.localizeddescription); } else { nslog(@"success"); }];
unfortunately, above rematch effort fails because of wrong status of player 2. resultant error message above is:
the requested operation not completed because match request invalid.
the next stack overflow problem suggests due errant match info described above: trouble using new rematchwithcompletionhandler method game center
in order solve problem, had programmatically load match info forcefulness matchoutcome of player 2 switch state of "won". so, instead of calling rematchwithcompletionhandler when user affirms prompt rematch, next when affirm prompt rematch:
[gkturnbasedmatch loadmatchwithid:currentmatch.matchid withcompletionhandler: ^(gkturnbasedmatch *match, nserror *error) { if (error) { nslog(@"in requestrematch, failed receive match data: %@", error.localizeddescription); } else { // received match data. request rematch [match rematchwithcompletionhandler: ^(gkturnbasedmatch *rematch, nserror *error) { if (error) { nslog(@"in requestrematch: rematchwithcompletionhandler. error creating rematch: %@", error.localizeddescription); } else { nslog(@"in requestrematch: rematch granted new matchid=%@. currentmatch was: %@", match.matchid, currentmatch.matchid); // rematch info } }]; } }];
ios game-center gkturnbasedmatch
Comments
Post a Comment