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)
}