I basically just followed this tutorial https://www.raywenderlich.com/7544-game-center-for-ios-building-a-turn-based-gametried. Instead of a turned-based game, I was trying to make a peer-to-peer real-time match. Here's my code:
let request = GKMatchRequest()
request.minPlayers = 2
request.maxPlayers = 2
request.defaultNumberOfPlayers = 2
request.recipientResponseHandler = { player, response in
// never being called
}
let vc = GKMatchmakerViewController(matchRequest: request)!
vc.matchmakerDelegate = self
present(vc, animated: true)
The GKMatchmakerViewController shows up correctly. And it can successfully find a match for me automatically. The only problem is that if I manually add a friend in the player slot and press start, it says it's waiting for the other player forever, but nothing shows up on my friend's phone. I don't even know what should it look like when the invitation happens.
I implemented GKLocalPlayerListener and GKMatchmakerViewControllerDelegate, but player(_ player: GKPlayer, didRequestMatchWithOtherPlayers playersToInvite: [GKPlayer])
and player(_ player: GKPlayer, didAccept invite: GKInvite)
are never called.
edit: I didn't see such callback to handle invitation before matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch)
is called, that's why I don't have code for match request subsystem. I saw GKInviteEventListener protocol in the documentation, and it told me to use GKLocalPlayerListener instead, who's methods never being called. I also read this documentation https://developer.apple.com/documentation/gamekit/finding_multiple_players_for_a_game. And I still don't see how to deal with match request subsystem.
What is the right way to invite a friend and make the match?
do not subclass GKMatchmakerViewController... in my case both my devices stayed on "connecting..." state for ever