0

I want to let the user to either create new match or join existing matches which are created using create new match, all to be done programmatically. My question is how can I force game center to only create a new match ? The code which apple provided in their document is:

-(IBAction)findProgrammaticMatch:(id)sender {
    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 2;
    request.maxPlayers = 2;
    [GKTurnBasedMatch findMatchForRequest:request withCompletionHandler:^(GKTurnBasedMatch *match,NSError *error) {
        if (match)
            // load gameplay
    }];
}

this code will create a new match if and only if there is no existing match, otherwise it will make auto-match.

mbrmj
  • 119
  • 10

1 Answers1

0

Use playerAttributes property on the GKMatchRequest:

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

if (wantsNewGame)
    request.playerAttribute = 0x0000FFFF;
else if (wantsJoin)
    request.playerAttribute = 0xFFFF0000;
else // don't care
    request.playerAttribute = 0xFFFFFFFF;

GKTurnBasedMatchmakerViewController *vc = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
kervich
  • 487
  • 3
  • 13