删除处于无效状态的GKTurnBasedMatch

问题描述:

我正在做一些尝试来尝试了解GameKit,我制作了一个简单的游戏和一个列出我的玩家匹配的界面。我试图在匹配时使用 removeWithCompletionHandler:方法添加删除游戏的功能,但是我在删除 GKTurnBasedMatch $ c时遇到问题$ c>似乎进入了无效状态。

I am doing some experimentation to try to learn about GameKit and I made a simple game and an interface which lists my player's matches. I am trying to add the ability to remove games using the removeWithCompletionHandler: method on the match, but I am having trouble removing a GKTurnBasedMatch which seems to have entered an invalid state.

有问题的比赛打印:

$0 = 0x1d590d20 <GKTurnBasedMatch 0x1d590d20 id:858d8257-cc49-4060-b1d8-38c09a929e3c status:Ended message: taken:2013-03-08 18:08:47 +0000 created:2013-03-08 03:24:14 +0000
current:<GKTurnBasedParticipant 0x1d58c020 - id:G:1717956303 (local player) status:Invited outcome:None lastTurn:(null)>
participants:
    <GKTurnBasedParticipant 0x1d58bc90 - id:G:1717239488 status:Done outcome:Quit lastTurn:2013-03-08 18:08:47 +0000>
    <GKTurnBasedParticipant 0x1d58c020 - id:G:1717956303 (local player) status:Invited outcome:None lastTurn:(null)>
>

这似乎表明比赛已经结束。然而,其中一个参与者的结果是:无,我被相信的文档所引导,对于已结束的游戏无效。试图简单地删除游戏给出:

Which seems to indicate that the match has been ended. However, one of the participants has the outcome:None, which I am led by the docs to believe is invalid for an ended game. Trying to simply remove the game gives:


由于一个或多个参数无效,无法完成请求的操作。

The requested operations could not be completed because one or more parameters are invalid.

尝试设置结果并结束游戏时:

While trying to set the outcomes and end the game gives:


请求的操作无法完成,因为会话处于无效状态。

The requested operation could not be completed because the session is in an invalid state.

我想也许我无法删除游戏因为本地玩家是主动参与者,但 participantQuitInTurnWithOutcome:... endTurnWithNextParticipants:... 两者都给错误:

I thought perhaps I could not remove the game because the local player is the active participant, but both participantQuitInTurnWithOutcome:... and endTurnWithNextParticipants:... both give the error:


由于会话处于无效状态,无法完成请求的操作。

The requested operation could not be completed because the session is in an invalid state.

。我做错了什么或者我以某种方式创造了一个不可移动的游戏?

as well. Am I doing something wrong or did I somehow create an unremovable game?

P.S。我也无法通过游戏中心提供的界面删除游戏,它们列在游戏结束部分下。

P.S. I am also unable to remove the games through the Game Center provided interface, where they are listed under the "Game Over" section.

This is how I managed to remove all invalid matches.

我检查了当前参与者的状态,如果被邀请,我调用了declineInviteWithCompletionHandler,否则我调用了participantQuitInTurnWithOutcome。

I checked the status of the current participant, if it's invited, I called declineInviteWithCompletionHandler, otherwise I called participantQuitInTurnWithOutcome.

在两个完成块中,我都调用了removeWithCompletionHandler来删除匹配。

In both completion blocks, I then called removeWithCompletionHandler to remove the match.

这会产生一些错误但是比赛仍然被删除,所以我的清单是干净的。

This generated a few errors but the matches were still removed so my list is clean.

这里有一个关于如何避免开始这种状态的解决方法。这样做的另一个好处是,如果邀请者在完成他/她的第一次转弯之前退出,被邀请者甚至都不会收到通知。

And here is a workaround on how to avoid getting to this state to begin with. This has the added benefit that the invitee never even get a notification if the inviter quits before finishing his/hers first turn.

在playerQuitForMatch中,首先结束转弯然后进入完成处理程序,立即退出匹配。像这样,

In playerQuitForMatch, first end the turn and then in the completion handler, immediately quit the match. Like so,

[match endTurnWithNextParticipants:[NSArray arrayWithObject:nextParticipant]
                                          turnTimeout:GKTurnTimeoutDefault
                                            matchData:nil completionHandler:^(NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                }

                                                [match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit
                                                                     withCompletionHandler:^(NSError *error) {
                                                                         if (error) {
                                                                             NSLog(@"%@" ,error);
                                                                         }
                                                                     }];
                                            }];