0

我对 endMatchInTurnWithMatchData 的调用导致连接到服务中断错误。关于寻找什么来诊断此问题的任何提示?Xcode 7.3.1,部署目标 9.3

-(void)sendGameOver {
    GKTurnBasedMatch *currentMatch = [[GameKitHelper sharedGameKitHelper] currentMatch];

    // set the game outcome property for the current participant
    GKTurnBasedMatchOutcome otherOutcome;
    if (self.youAre == game.winningPlayer) {
        [currentMatch.currentParticipant setMatchOutcome:GKTurnBasedMatchOutcomeWon];
        otherOutcome = GKTurnBasedMatchOutcomeLost;
    } else {
        [currentMatch.currentParticipant setMatchOutcome:GKTurnBasedMatchOutcomeLost];
        otherOutcome = GKTurnBasedMatchOutcomeWon;
    }

    // all other (only one other) participants get opposite outcome
    for (GKTurnBasedParticipant *nextParticipant in currentMatch.participants) {
        if (![nextParticipant isEqual:currentMatch.currentParticipant]) {
            [nextParticipant setMatchOutcome:otherOutcome];
        }
    }

    // prepare match data
    NSDictionary *turn = [NSDictionary dictionaryWithObjects:@[game]
                                                 forKeys:@[gameKey]];
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:turn];

    NSArray *achievements = [self achievementsToReport:currentMatch];
    NSArray *scores = [self scoresToReport:currentMatch];

    [currentMatch endMatchInTurnWithMatchData:data scores:scores achievements:achievements completionHandler:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"%@", error);
            [self setGamePopUpMessage:@"Oops, there was a problem.  Try that again."];
        }
    }];

}
4

2 回答 2

0

最初的问题是我自己创建了一系列成就,在所有情况下都使用 GKAchievement initWithIdentifire,即使是在之前的比赛中已经为玩家报告的成就。正确的做法是首先调用 loadAchievementsWithCompletionHandler 来获取玩家已知的所有成就,然后更新相关的成就。如果需要,可以将新的 GKAchievement 添加到该数组中。但关键是正确初始化数组。一旦我解决了所有这些问题,我就可以使用 endMatchInTurnWithMatchData 正确发送成就数组:分数:成就:completionHandler:并且不再收到“名为 com.apple.gamed 的连接服务被中断”的原始错误。

然而...

我的游戏是一个两人游戏,有人可能被迫转弯(或意外转弯)导致他们立即输掉比赛。在那种情况下,我想增加他们的对手(刚刚获胜)的成就。但是,您似乎无法增加对手的成就,因为您无法知道他们之前的成就水平。

我的解决方法并不理想,即轮到输掉比赛的玩家报告他们可能获得的任何成就(目前没有,但你永远不知道......)。未轮到获胜的玩家将在收到“matchEnded”消息后报告他们的成就。不幸的是,这意味着如果他们从不打开游戏,他们就不会增加他们的成就。不理想。

于 2016-07-31T20:09:46.720 回答
0

不知何故,问题似乎在成就的报告中。如果我为成就发送一个空数组,错误就消失了。但是,一旦我尝试使用 endMatch 传递成就信息,错误又回来了。

因此,如果我使用,我会继续收到错误“与名为 com.apple.gamed 的服务的连接被中断”

endMatchInTurnWithMatchData: scores: achievements: completionHandler:

但是,如果我使用(作为解决方法)

endMatchInTurnWithMatchData: completionHandler:

紧随其后的是:

GKAchievement reportAchievements: withCompletionHandler:

然后一切似乎都正常工作。

于 2016-07-28T17:05:59.107 回答