In a SwiftUI game using a UIViewControllerRepresentable; When presenting a GKTurnBasedMatchmakerViewController view with showExistingMatches set to true, sometimes the Invite view is presented and not the existing matches, dismissing it or even inviting someone does not stop it from presenting the next time it's called.
Sometimes logging out and of Game Center and back in fixes it other times a restart of the device is required.
typealias ViewControllerRepresentable = UIViewControllerRepresentable
struct GameCenterView: ViewControllerRepresentable {
...
// Creates a new view controller
func makeUIViewController(context: Context) -> GKTurnBasedMatchmakerViewController {
let request = GKMatchRequest()
request.minPlayers = 2
request.maxPlayers = 2
request.inviteMessage = "Would you like to play a game of X?"
request.defaultNumberOfPlayers = 2
let viewController = GKTurnBasedMatchmakerViewController(matchRequest: request)
viewController.showExistingMatches = true
viewController.turnBasedMatchmakerDelegate = context.coordinator
return viewController
}
...