Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Game Kit Turn Based Match Programatic Rematch

I have a 2-player, iOS turn-based game that uses the game center and GKTurnbasedMatch.

Is there a way to programmatically rematch an opponent after a match has finished?

I would like to give the players one-button access to starting a new match with each other.

If there is not a one button approach, what are some potential alternatives?

like image 540
Jay Haase Avatar asked Aug 27 '12 19:08

Jay Haase


1 Answers

Indeed it appears a full programmatic solution is being ignored by Game Center. A pain, no doubt. Try the following in your @selector(doRematchTap)... or some equivalent:

    NSMutableArray *playerIds = [NSMutableArray array];
    GKTurnBasedParticipant *otherPlayer = /* Get the other player some way */;
    GKTurnBasedParticipant *myParticipant = /* Get yourself a very similar way*/;

    [playerIds addObject:myParticipant.playerID];
    if (otherPlayer.playerID) {
        [playerIds addObject:otherPlayer.playerID];
    }// sanity check

    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.playersToInvite = playerIds;
    request.minPlayers = 2;
    request.maxPlayers = 2;

    GKTurnBasedMatchmakerViewController *tbmcv = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
    tbmcv.showExistingMatches = NO;
    tbmcv.turnBasedMatchmakerDelegate = /* Your normal delegate for the callbacks */;

    [self presentViewController:tbmcv
                       animated:YES
                     completion:^{
                      }];

Important to note the showExistingMatches = NO, which will jump the view controller right into matchmaking mode with the correct user pre-selected (it seems), and not show the user's existing matches.

like image 97
Lestrade Avatar answered Sep 30 '22 23:09

Lestrade