iOS - 沙盒中重新匹配 WithCompletionHandler 的问题

iOS - issue with rematchWithCompletionHandler in Sandbox

我有以下代码:

   if(tappedItem.match.status == GKTurnBasedMatchStatusEnded){
        [[GameKitHelper sharedGameKitHelper] findMatchWithViewController:self delegate:self debug:false  invite:tappedItem.player];
        return;
        NSLog(@"Participants %@", [tappedItem.match.participants description]);

        [tappedItem.match rematchWithCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
         {
             if (error) {
                 NSLog(@"%@", error);
             }

             else
             {
                 [[GameKitHelper sharedGameKitHelper] setMatch:tappedItem.match];
                 [[NSNotificationCenter defaultCenter]
                  postNotificationName:ShowGameScreen
                  object:tappedItem.match];
             }

         }];
    }

我有很多人在启用沙盒的情况下通过 TestFlight 对其进行 Beta 测试,但由于某种原因,我在尝试重新匹配时遇到以下错误:

{GKServerStatusCode=5121, NSLocalizedDescription=The requested operation could not be completed because the player is invalid., NSUnderlyingError=0x17045cdd0 "The operation couldn’t be completed. status = 5121, Invitation from: 224002977 to: 225851510 is not allowed because they are neither friends nor have recently played"}

比赛正常结束,所以不是:

[_match
        endMatchInTurnWithMatchData:data
        scores:scores
        achievements:nil
        completionHandler:^(NSError *error) {}];

我认为这是 Sandbox 的一个孤立问题,但除非我可以对其进行测试,否则我不确定它是否会在发布后正常工作。

编辑#2:

这是 tappedItem.match 对象:

    <GKTurnBasedMatch 0x174250200 -
matchID:0049f124-b8c3-43d8-9964-beaf58af69f8
bundleID:--- REMOVED ---
status:GKTurnBasedMatchStatusEnded
message:''
creationDate:2015-06-24 23:12:31 +0000
currentParticipant:(null)
participants:<GKTurnBasedParticipant 0x174205450 -
playerID:G:225851510
status:Done
matchOutcome:Won
lastTurnDate:2015-06-24 23:12:32 +0000
timeoutDate:(null)>,
<GKTurnBasedParticipant 0x174205460 -
playerID:G:224002977 (local player)
status:Done
matchOutcome:Lost
lastTurnDate:2015-06-24 23:16:56 +0000
timeoutDate:(null)>
matchData.length:295
matchDataMaximumSize:65536
exchanges:(null)>

如您所见,比赛是几个小时前才结束的。只要他们是朋友,这就可以正常工作,但我需要先测试重赛功能,然后才能上线。

编辑#1:

我在使用 findMatchForRequest 时收到相同的错误代码:

GKMatchRequest *request = [[GKMatchRequest alloc] init];
    if(player != NULL)
        request.recipients= [NSMutableArray arrayWithObject:player];
    request.minPlayers = 2;
    request.maxPlayers = 2;

根据错误,"they are neither friends nor have recently played",最近还玩过

我在这里抓住了救命稻草,但您的编辑看起来类似于我在 GKTurnBasedMatchTurn 末尾尝试构建 nextParticipants 数组时遇到的问题。它没有给我一个连贯的错误,它只是不断地把转牌发回给同一个玩家。根源似乎是:Game Center 不喜欢您将指向它之前发送给您的不可变对象的指针传递给它。

我不得不改变

NSMutableArray *nextPlayers = (NSMutableArray *)theMatch.participants;
..some sorting logic deleted for brevity...
[theMatch endTurnWithNextParticipants:nextPlayers
                          turnTimeout:GKTurnTimeoutDefault
                            matchData:updatedMatchData
                    completionHandler:^(NSError *error)
{

收件人:

NSMutableArray *nextParticipants = [NSMutableArray new];
for (GKTurnBasedParticipant *participant in theMatch.participants)
{
    ...some sorting logic deleted for brevity...
    [nextParticipants addObject:participant];
}

[theMatch endTurnWithNextParticipants:nextParticipants
                          turnTimeout:GKTurnTimeoutDefault
                            matchData:updatedMatchData
                    completionHandler:^(NSError *error)
{

你的代码块没有显示你从哪里得到 player,所以我不清楚这些是新的还是重复使用的对象。我想知道这段代码是否

if(tappedItem.match.status == GKTurnBasedMatchStatusEnded){
    [[GameKitHelper sharedGameKitHelper] findMatchWithViewController:self delegate:self debug:false  invite:tappedItem.player];

和这个代码

if(player != NULL)
    request.recipients= [NSMutableArray arrayWithObject:player];

是问题所在。如果您尝试创建播放器的副本并将其传递给重新匹配和 findMatch 调用,会发生什么情况?