簡體   English   中英

重試endTurnWithNext參與者

[英]Retry endTurnWithNextParticipants

我想處理endTurnWithNextParticipants失敗的錯誤情況。 因此,我通過在本文結尾處調用cacheFailedEndTurnWithNextParticipants方法來存儲匹配數據。 我提供的功能僅供參考。

問題是我不知道如何使用uncache方法還原數據。 我怎樣才能加載GKTurnBasedPlayers為nextParticipants列表? 我現在使用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];
  }
}

可以從比賽中獲取參與者,然后從該數組中檢索玩家ID,最后更新比賽中的參與者屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM