4

在我的回合制游戏中,我收到以下错误,表明会话处于无效状态并且游戏未处于活动状态:

2014-06-26 15:46:04.684 myApp[14498:60b] Error Domain=GKErrorDomain Code=24 
"The requested operation could not be completed because the session is in an invalid state." 
UserInfo=0x16d074a0 {GKServerStatusCode=5101, NSUnderlyingError=0x16d09fb0 
"The operation couldn’t be completed. status = 5101, Game is not active, session state is Complete", 
NSLocalizedDescription=The requested operation could not be completed because the session is in an invalid state.}

当我调用 endMatchInTurnWithMatchData:completionHandler: 时发生此错误(此时轮到本地玩家,他正在退出游戏)。但是,我不明白当前状态有什么问题。在调用此方法之前,我打印了匹配对象。以下是内容:

currentMatch object is: 
<GKTurnBasedMatch 0x16d5e690 - matchID:c53a9ef1-d4ce-4da3-a2f3-9220df917615 bundleID:com.myCompany.myApp 
status:GKTurnBasedMatchStatusOpen message:'' creationDate:2014-06-26 20:43:17 +0000 
currentParticipant:
<GKTurnBasedParticipant 0x16d430d0 - playerID:G:1386520835 (local player) status:Done matchOutcome:Quit lastTurnDate:2014-06-26 20:43:35 +0000 timeoutDate:(null)> 
participants:
<GKTurnBasedParticipant 0x16d430d0 - playerID:G:1386520835 (local player) status:Done matchOutcome:Quit lastTurnDate:2014-06-26 20:43:35 +0000 timeoutDate:(null)>,
<GKTurnBasedParticipant 0x16d526c0 - playerID:G:109161898 status:Active matchOutcome:Won lastTurnDate:2014-06-26 20:43:54 +0000 timeoutDate:(null)> matchData.length:712 matchDataMaximumSize:65536 exchanges:(null)>

如您所见,比赛的状态是 GKTurnBasedMatchStatusOpen。如果我没记错的话,这告诉我游戏是活跃的。此外,每个参与者都有一个非“无”的 matchOutcome,这是发送 endMatchInTurnWithMatchData:completionHandler: 之前的要求。

这是我在本地玩家退出时结束比赛的代码序列:

[currentMatch participantQuitInTurnWithOutcome:GKTurnBasedMatchOutcomeQuit nextParticipants:currentMatch.participants turnTimeout:1.0 matchData:data completionHandler:nil];

NSLog(@"currentMatch object is: %@", currentMatch);

[currentMatch endMatchInTurnWithMatchData: data
                        completionHandler: ^(NSError *error) {
                           if (error) {
                               NSLog(@"%@", error);
                           }
                           else {
                               NSLog(@"match ended successfully");
                           }
 }];

请告诉我我结束比赛的方法有什么问题,或者导致此错误的会话/比赛状态有什么问题,或者向我建议我还应该验证什么以确定问题的根源。

4

1 回答 1

1

我在这里聚会很晚了,但问题是ParticipantQuitInTurnWithOutcome先打电话。一旦你这样做了,你就不再是回合的拥有者了。然后,当您尝试endMatchInTurnWIthMatchData(关键是“inTurn”子句)时,您不再是所有者,因此您不处于这样做的有效状态。

于 2016-03-26T18:33:02.397 回答