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
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
GKLocalPlayerListenerprotocol is giving alot of people trouble: Another question about GTTurnBasedMatchAnyways:
The
GKTurnbasedMatchmakerViewControllerDelegateprotocol 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
GKTurnbasedMatchmakerViewControllerDelegatehandle any of the actual matchmaking methods; they instead gave those responsibilities to theGKTurnBasedEventListenerprotocol (underGKLocalPlayerListener).So after you do what you have done above make sure to do the following:
GKLocalPlayerListenerprotocol.[[GKLocalPlayer localPlayer] registerListener:self];- (void)player:(GKPlayer *)player receivedTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive, from theGKLocalPlayerListenerprotocolWhen 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.