Search code examples
ioscocos2d-iphonegame-centergamekit

Game Center Sandbox : "Could not create game" issue


I'm currently developing a turn based game using Game Center to handle the online functionalities (for matchmaking and turns handling).

I'm using two sandbox accounts - one on my 3gs and one on the ios Simulator. I've been testing my app using the GKTurnBasedMatchMakerViewController to do the match making for a while without any problems, but I'm now stuck with an issue:

Every time I want to invite another player for a new (with either one or the other player), the GKTurnBasedMatchMakerViewController displays a UIAlertView stating :

Could not create game - Please remove an existing game and try again.

The thing is, I've deleted all the matches for each player (none of them has any game in his list (not even a closed game). So none of the user is in any match at the moment.

In my GKTurnBaseMatchMakerViewControllerDelegate the turnBasedMatchmakerViewController:didFailWithError: is not called. The only called function called in the delegate- when I click the OK button on the UIAlertView - is turnBasedMatchmakerViewControllerWasCancelled:

The only thing I can think of is that my games are actually not removed from GameCenter, but as I'm removing them using the GKMatchMakerViewController UI, I barely think so.


When quitting from a turn-based match I've implemented the turnBasedMatchmakerViewController:playerQuitForMatch: like this:

- (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController playerQuitForMatch:(GKTurnBasedMatch *)match
{
  if ( [self isLocalPlayerCurrentPlayerForMatch:match] ) {

    NSData* endData = match.matchData;

    for (GKTurnBasedParticipant* participant in match.participants) {
      participant.matchOutcome = GKTurnBasedMatchOutcomeWon;
    }
    match.currentParticipant.matchOutcome = GKTurnBasedMatchOutcomeLost;

    [match endMatchInTurnWithMatchData:endData 
                     completionHandler:^(NSError *error) {
                       if (error) {
                         NSLog(@"%@",error.description);
                       }
                     }];
  }  

}

(NB: I only have two players in the game)

where isLocalPlayerCurrentPlayerForMatch is:

- (BOOL) isLocalPlayerCurrentPlayerForMatch:(GKTurnBasedMatch*)match
{
  return [[[GKLocalPlayer localPlayer] playerID] isEqualToString:match.currentParticipant.playerID];
}

Has anyone encountered and found a solution to this issue? Am I doing something wrong here, or is it so obvious I just can't see it?

Thank you very much for any comments that would help me find the root of that issue.

Update

Thanks to @kaan-dedeoglu I managed to know that both users had an empty list of matches (consistent with the displayed state).

I also created a third Sandbox account. Naming the two first accounts A and B, C the third one.

State 1:

  1. A and B are not linked to any match.
  2. A and B are both getting the "Could not create game" error while creating any game (A invites B, A||B invites other player, A||B creates new automatch).

State 2:

  1. C (working account) can invite B and normally plays a party with B.
  2. C (working) can invite B for another simultaneous party
  3. C (working) invites A to play.
  4. A can't play (can't access the list of current matches, the GKTurnBasedMatchMakerViewController directly goes to the creation of a new game).
  5. C is not working anymore.
  6. A, B and C are now stuck in "Could not create game" error.

As a complement here is how I initialize my GKTurnBasedMatchMakerViewController, but I don't see that being wrong.

- (void) displayMatchMakerVC
{

  if (! [[GKLocalPlayer localPlayer] isAuthenticated] ) return;

  GKMatchRequest* request = [[[GKMatchRequest alloc] init] autorelease];
  int nbPlayers = 2;
  request.minPlayers = nbPlayers;
  request.maxPlayers = nbPlayers;


  GKTurnBasedMatchmakerViewController*  matchMakerVC = [[[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
  matchMakerVC.turnBasedMatchmakerDelegate = self;
  matchMakerVC.showExistingMatches = YES;

  [[CCDirector sharedDirector] presentModalViewController:matchMakerVC animated:YES];
}

NB: I'm not using ARC, could that be related to a memory issue? I'm not really a memory management guru, but it seems correct to my understanding.

Any idea of how this could be related to my code and not to game center? Thank you very much for any answer that could help me go further.

Update 2: turnbasedMatchmakerViewController:didFindMatchMethod:

Here's my turnbasedMatchmakerViewController:didFindMatchMethod: method.

- (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match
{
  BLTheme* theme = [[[BLGameConfig sharedConfig] localPlayer] userTheme];
  GameSceneRemoteGCLoader* loader = [[GameSceneRemoteGCLoader alloc] initWithGKMatch:match andTheme:theme];
  [viewController dismissViewControllerAnimated:NO completion:^{}];
  [[CCDirector sharedDirector] replaceScene:loader];

}

When I'm launching an automatch it's launching the exact same error "Could not create game - Please remove an existing game and try again.".


Solution

  • This may or may not be the solution to your problem, but I had a similar issue and solved it in the following way.

    It seems that either by default, or somehow, Game Center treats apps with differing CFBundleVersion (build number, not version number, or CFBundleShortVersionString) values as incompatible with one another, and thus does not show matches between apps with incremented build numbers. (Often, developers increment this number as new ad hoc builds or stable releases are distributed during development, so this is quite unfortunate).

    To find and remove the "missing" games, I decremented my CFBundleVersion value (which revealed the games), and then deleted the offending matches.

    Alternatively, tweaking some settings in iTunes Connect seems to have removed this CFBundleVersion incompatibility. It takes a while to propagate, but I think what did it was tapping on my app, tapping on View Details, making sure the Game Center switch is set to "Enabled", and making sure there is an item in the "Multiplayer Compatibility" table. You could also play with the possibilities within the "Manage Game Center" button from the original app screen, but I think the "Multiplayer Compatibility" setting is what finally allowed me to see all the "old" matches that were previously hidden.

    Good luck!