Frage

I am using custom view to show the list of matches in my turn based game. With the custom view I am having issues showing the list of current games the player is involved when the device is offline. But when I check the game center default view the matches show fine even when offline. The code I am using to populate my array is as follows (extracted from the book by Ray Wenderlich)

[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error)
     {

         if (error)
         {
             NSLog(@"%@", error.localizedDescription);
         }
         else
         {

             NSMutableArray *myMatches = [NSMutableArray array];
             NSMutableArray *otherMatches = [NSMutableArray array];
             NSMutableArray *endedMatches = [NSMutableArray array];

             for (GKTurnBasedMatch *m in matches)
             {
                 GKTurnBasedMatchOutcome myOutcome;
                 for (GKTurnBasedParticipant *par in m.participants)
                 {
                     if ([par.playerID isEqualToString: [GKLocalPlayer localPlayer].playerID])
                     {
                         myOutcome = par.matchOutcome;
                     }
                 }

                 if (m.status != GKTurnBasedMatchStatusEnded && myOutcome != GKTurnBasedMatchOutcomeQuit)
                 {
                     if ([m.currentParticipant.playerID
                          isEqualToString:[GKLocalPlayer localPlayer].playerID])
                     {
                         [myMatches addObject:m];
                     }
                     else
                     {
                         [otherMatches addObject:m];
                     }
                 }
                 else
                 {
                     [endedMatches addObject:m];
                 }
             }
             // 6
             allMyMatches = [[NSArray alloc]initWithObjects:myMatches,otherMatches,endedMatches, nil];

             NSLog(@"%@",allMyMatches);


             [self.tableView reloadData];

         }
     }];

Any ideas why this is happening?

War es hilfreich?

Lösung

loadMatchesWithCompletionHandler: will talk to the Game Center servers and I would expect it to fail if your device is offline. You are checking for error to be not nil. Is error.localizedDescription telling you you're not connected?

My bet would be that the Game Center default view will show you matches that it cached from the last time you were connected. You could do this too, but remember that you would also have to cache the matchData. Not sure how important that would be since you won't be able to submit your turn anyways.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top