1

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?

user2327003
  • 103
  • 5

1 Answers1

1

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.

s.bandara
  • 5,636
  • 1
  • 21
  • 36
  • I am not worried about ending the turn when the user is offline. I have set the conditions that if user is offline then they get an alert that they will need to try again later. I would like to load the cached data so that the user can see the games they are involved in and atleast complete their turn. How do I load the cached matches/data. – user2327003 May 23 '13 at 05:46
  • Doh!!! I just realised what you meant about checking for error. Thanks for your help. – user2327003 May 23 '13 at 08:00