How is GKTurnBasedMatchmaker used?

167 views Asked by At

I'm trying to create a simple turn based 2 player game, but am struggling to understand how to use GKTurnBasedMatchmaker

Here's the steps I have so far:

  • Authenticate Local Player
  • Make my view controller the GKTurnbasedMatchmakerViewControllerDelegate
  • Present the matchmaking view controller like so:

    self.match.minPlayers = 2;
    self.match.maxPlayers = 2;
    self.match.defaultNumberOfPlayers = 2;
    
    
    let mmVC = GKTurnBasedMatchmakerViewController(matchRequest: match);
    mmVC.turnBasedMatchmakerDelegate = self;
    self.view?.window?.rootViewController?.present(mmVC, animated: true, completion: nil);
    

I now have no idea what to do after this.

How can I tell if the matchmakerViewController successfully found a match and I should transition to the game?

The didFindMatch callback seemed like the obvious solution, but it's deprecated

1

There are 1 answers

0
Ishmael King On

I am also having trouble with GKTurnBasedMatch. But I may be able to help you take a few steps forward.

First look at some of the other answered questions related to this for problems you may have down the road. Apparently the whole GKLocalPlayerListener protocol is giving alot of people trouble: Another question about GTTurnBasedMatch

Anyways:

The GKTurnbasedMatchmakerViewControllerDelegate protocol now only has two methods associated with it. There is one for canceling the VC and one to handle an error.

If looks like Apple may have chosen to not to let GKTurnbasedMatchmakerViewControllerDelegate handle any of the actual matchmaking methods; they instead gave those responsibilities to the GKTurnBasedEventListener protocol (under GKLocalPlayerListener).

So after you do what you have done above make sure to do the following:

  1. Make you main VC adhere to the GKLocalPlayerListener protocol.
  2. Register your VC via [[GKLocalPlayer localPlayer] registerListener:self];
  3. Implement - (void)player:(GKPlayer *)player receivedTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive, from the GKLocalPlayerListener protocol

When you start a new game this function should fire.

Unfortunately, I am still trying to overcome other obstacles I have hit with GK, good luck to you.