0

I'm trying to create a custom view controller to display active games to the user (similar to what Letterpress does).

I am currently trying to subclass GKTurnBasedMatchmakerViewController except I don't know how to hide the default elements (for inviting/showing existing games) and to add my own. I have currently been playing around with logging things to ensure I can access the active matches, current player IDs, etc (which I have recently figured out) but I am stuck on how to start with the interface.

Not sure what code, if any would be relevant at this point. Please let me know.

Looking to: Hide current elements. I'm assuming I can build the interface as I would for any other application after that.

Thanks,

  • Steven
Steven Ritchie
  • 228
  • 1
  • 2
  • 12

1 Answers1

1

I don't think its a good idea to subclass. Start with a clean UIViewController and build the UI from there. Then implement all the necessary methods.

Set yourself as delegate:

   [GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate = self;

so you get delegate event, such as:

handleInviteFromGameCenter
handleTurnEventForMatch
handleMatchEnded
etc. 

Add a UITableView, and load all matches from Game center:

   [GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error) {
     // Add matches to table view
   }];

Don't forget to authenticate the player first:

GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *loginVC, NSError *error)
{

};

Star a match programatically:

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
[GKTurnBasedMatch findMatchForRequest:request withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error)
 {

 }];

etc. Look at the doc for the full API.

BlackMouse
  • 4,442
  • 6
  • 38
  • 65
  • How do you suggest I load a match programatically, from the tableView:didSelectRow method? – Steven Ritchie Dec 17 '13 at 03:36
  • You don't. Call loadMatchesWithCompletionHandler, and you get back all the matches. You then save the array of matches in an ivar, and populate the tableView from that. – BlackMouse Dec 17 '13 at 10:42