iosxcodegame-centergkturnbasedmatch

Game Center - turn based game issue


I'm developing a turn based game for iOS with a custom interface and i discovered a very odd problem with my matchmaking interface. The following code is used to display a list of active matches, i authenticate the user, then get the list of matches and the last step is to load the match so i can display all the info.

The problem appears when i build the app, go to the matchmaking view controller and leave it alone for 5 minutes; then when i try deleting a match i get an error in loadingMatchWithID:

Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)

The code works fine every time, deleting, creating matches, refreshing, but if i leave the view controller alone for 5 minutes and then try to delete i get the error. The odd part is the that the localPlayer passes an authentication test, and loads correctly the matches array then stops in loading the match.

One other thing happens, if the error appears and i push the home button and open back the app, everything words again and the matches are loaded correctly.

I think i a problem with the authentication, but where is the mistake ?

UPDATE: The issue appears in iOS7, but in iOS6 it works !

[localPlayer authenticateWithCompletionHandler:^(NSError *error)
    {
       if (error)return; 
       [GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error)
       {
          for (int i = 0; i < matchesArray.count; i++)
          {
             [GKTurnBasedMatch loadMatchWithID:[[matchesArray objectAtIndex:i]matchID] withCompletionHandler:^(GKTurnBasedMatch *updatedMatch, NSError *error)
             {
                 if (error != nil)
                 {
                     NSLog(@"Error: %@",error.description);
                 }
              }];
           }
       }];
    }];

Solution

  • I found what was the issue after many days of searching and testing everything. The problem was with quitting and then removing a match, the removeWithCompletionHandler: was inside the participantQuitInTurnWithOutcome: and somehow these actions would log out the player from game center without any notice, and the odd thing was that all the .isAuthenticated test would succeed.

    Probably the most frustrating part was that the code worked for the most part, and worked every time on devices below iOS 7.