2017-05-16 8 views
0

Ich möchte den Fehlerfall behandeln, wo endTurnWithNextParticipants fehlschlägt. Ich speichere daher Match-Daten, indem ich die cacheFailedEndTurnWithNextParticipants Methode am Ende dieses Posts aufrufen. Ich habe die Funktion nur als Referenz zur Verfügung gestellt.Retry endTurnWithNextParticipants

Das Problem ist, dass ich nicht weiß, wie ich die Daten in der Uncache-Methode wiederherstellen soll. Wie kann ich die GKTurnBasedPlayers für die nächste Teilnehmerliste laden? Ich benutze GKPlayer::loadPlayersForIdentifiers jetzt, aber ich bekomme die folgende Warnung:

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

Wie ich GKTurnBasedParticipants von IDs laden kann?

Soll das Rücksenden auf andere Weise erfolgen?

-(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]; 
    } 
} 

Antwort

0

Es ist möglich, die Teilnehmer aus dem Spiel zu bekommen, und dann Spieler-IDs aus dem Array abzurufen und aktualisieren schließlich die Teilnehmer im Spiel zuschreiben.