重试endTurnWithNextParticipants

时间:2017-05-16 16:38:30

标签: ios gamekit gkturnbasedmatch

我想处理endTurnWithNextParticipants失败的错误情况。因此,我通过在本文末尾调用cacheFailedEndTurnWithNextParticipants方法来存储匹配数据。我提供的功能仅供参考。

问题是我不知道如何在uncache方法中恢复数据。如何为nextParticipants列表加载GKTurnBasedPlayers?我现在使用GKPlayer::loadPlayersForIdentifiers,但收到以下警告:

"/Users/eternity/Documents/Xcode/DominationSK/DominationSK/GKMatchCache.m:134:74: Incompatible pointer types sending 'NSArray<GKPlayer *> * _Nullable' to parameter of type 'NSArray<GKTurnBasedParticipant *> * _Nonnull'"

如何从ID中加载GKTurnBasedParticipants

这种转发应该以另一种方式完成吗?

-(void)uncache
{
  if (_cache.count > 0)
  {
    NSDictionary *d = _cache[0];
    [_cache removeObjectAtIndex:0];

    [GKTurnBasedMatch loadMatchWithID:d[MATCH_ID]
                withCompletionHandler:^(GKTurnBasedMatch * _Nullable match, NSError * _Nullable error) {
                  if (error == nil)
                  {
bad load method --> [GKPlayer loadPlayersForIdentifiers:d[PARTICIPANTS]
                                  withCompletionHandler:^(NSArray<GKPlayer *> * _Nullable nextParticipants, NSError * _Nullable error) {
                                    if (error == nil)
                                    {
                                      NSNumber *timeout = d[TIMEOUT];
warning -->                          [match endTurnWithNextParticipants:nextParticipants
                                                            turnTimeout:timeout.longValue
                                                              matchData:d[DATA]
                                                      completionHandler:^(NSError * _Nullable error){
                                                      // This is not finished
                                                      }];

                                    }
                                    else
                                    {
                                      [self addToCache:d]; // TODO: Add time to live
                                    }
                                  }];
                  }
                  else
                  {
                    [self addToCache:d]; // TODO: Add time to live
                  }
                }];
  }
}

// Just for reference
-(void)cacheFailedEndTurnWithNextParticipants:(GKTurnBasedMatch*)match
                                 participants:(NSArray<GKTurnBasedParticipant*>* _Nonnull)nextParticipants
                                  turnTimeout:(NSTimeInterval)timeout
                                    matchData:(NSData* _Nonnull)matchData
                                        error:(NSError* _Nonnull)error
{
  if ([self shallBeCached:error])
  {
    NSMutableArray *playerIds = [[NSMutableArray alloc] init];
    for (GKTurnBasedParticipant *p in nextParticipants)
    {
      [playerIds addObject:p.player.playerID];
    }
    NSDictionary *d = @{MATCH_ID : match.matchID,
                        PARTICIPANTS : playerIds,
                        TIMEOUT : [NSNumber numberWithLong:timeout],
                        DATA : matchData};

    [self addToCache:d];
  }
}

1 个答案:

答案 0 :(得分:0)

可以从匹配中获取参与者,然后从该数组中检索玩家ID,最后更新匹配中的参与者属性。