1

I've set up GameCenter turn-based matches for my game. Right now I'm just trying to display a list of the current matches for the current GK player.

Here's my code:

  GKTurnBasedMatch.loadMatchesWithCompletionHandler { (matchesOpt, errorOpt) in

    if let error = errorOpt {
      print("Error loading matches: \(error.localizedDescription)")
    } else if let matches = matchesOpt {
      self.matches = matches
      self.gamesTableView.reloadData()
    } else {
      print("Matches array is nil")
    }
  }
}

The third case is always hit, the matches array is nil.

I think there should be matches. I'm using

GKTurnBasedMatch.findMatchForRequest 

to start matches, and it is succeeding. Furthermore, if I note the matchId of the match from findMatchForRequest, and then I call

GKTurnBasedMatch.loadMatchWithID(matchId)

it finds the match, with the correct match data and everything.

Does anyone know how I can get loadMatchesWithCompletionHandler to return the same games that I can retrieve by id?

Edit: Here's the authentication code:

GKLocalPlayer.localPlayer().authenticateHandler = { (viewControllerOpt, errorOpt) in

  NSLog("GK local player authentication finished. Error: \(errorOpt)")
  if let viewController = viewControllerOpt {
    self.presentViewController(viewController, animated: true, completion: nil)
  }

  GKLocalPlayer.localPlayer().registerListener(self)

} 
7
  • Can you add the code where you authenticate the local user?
    – Thunk
    Apr 8, 2016 at 18:32
  • Another thing to check, in findMatchForRequest and loadMatchWithID completion handlers, try dumping the participants array to see what status the local player is in.
    – Thunk
    Apr 8, 2016 at 18:47
  • Edit: Added authentication code.
    – Michael B
    Apr 9, 2016 at 14:03
  • @Thunk, both immediately after the match is created, and also when it's retrieved with loadMatchWithID, the local player has status Active. The unmatched second player has status Matching.
    – Michael B
    Apr 9, 2016 at 14:23
  • probably not related to this problem, but please note in your auth handler: when the error is set, the viewController will be nil. So, they way you have that coded, if an error occurs you will print a message then immediately attempt to register the unauthenticated listener. That's probably not the problem here, but could bite you later. For more info, see stackoverflow.com/a/35677324/1641444.
    – Thunk
    Apr 10, 2016 at 7:24

1 Answer 1

1

It seems multiple people encountered this recently. Not sure if it's relevant, but the examples cited have always been using swift. Based on How to list all available GKTurnBasedMatches for a player? it looks like just creating a leaderboard will clear the problem.

Based on the thread at https://stackoverflow.com/a/34056115/1641444, it appears that sometimes Game Center gets stupefied and, for whatever reason, creating a leaderboard/achievement, or even just changing the default, kick starts it back into action.

1
  • Thunk is right, this fixed it for me. Go to iTunes Connect > Your App > App Store tab > find your app version > toggle the Game Center switch and add a leaderboard.
    – Bokoskokos
    May 22, 2016 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.