7

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?

Jay Haase
  • 1,979
  • 1
  • 16
  • 36
  • 2
    Good news! This is now very easy to do with iOS6 just use the GKTurnBasedMatch's rematchWithCompletionHandler. – Jay Haase Oct 03 '12 at 21:30

2 Answers2

4

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.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Lestrade
  • 106
  • 2
  • Thanks! The trick was to set showExistingMathes to NO. It's not exactly what I wanted (the user still has to click "Next" and "Send, but it does allow for much easier rematches. – Jay Haase Sep 07 '12 at 14:01
  • 1
    iOS6 has a new API for performing a rematch without requiring the game center interface. The method is: GKTurnBasedMatch->rematchWithCompletionHandler – Jay Haase Sep 24 '12 at 07:57
1

I don't have the whole solution, but a idea for you:

Every Player has a unique player-ID, that you can get, if you store it away after a

didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID

Now you can start programmatically a new match and invite this player. He will be asked if he wants a rematch and then you can play again.

I know this is not much of code or concrete advise, but maybe it's enough information to find the rest in the GameKit Class Reference.

I wonder if you can work it out, tell me if you did and good luck!

Edit:

I have searched in the references and found this:

- (void) loadPlayerData: (NSArray *) identifiers

I didn't tried it out myself, but you should get the player this way again, if you store his identifier in an array and pass it to this function.

I hope they bring some changes in iOS6 for Game Center, that you can make your matches programmatically in your own way...

louis.leon
  • 114
  • 6
  • I don't think this is currently possible. The method I know for submitting a match request programmatically is findMatchForRequest:withCompletionHandler. It has the following statement in its documentation: The match request’s playersToInvite property is ignored; to invite a specific set of players to the match, you must display the standard user interface. – Jay Haase Sep 06 '12 at 16:39