In my SceneKit game I'm able to connect two players with GKMatchmakerViewController
. Now I want to support the scenario where one of them disconnects and wants to reconnect. I tried to do this with this code:
nonisolated public func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) {
Task { @MainActor in
switch state {
case .connected:
break
case .disconnected, .unknown:
let matchRequest = GKMatchRequest()
matchRequest.recipients = [player]
do {
try await GKMatchmaker.shared().addPlayers(to: match, matchRequest: matchRequest)
} catch {
}
@unknown default:
break
}
}
}
nonisolated public func player(_ player: GKPlayer, didAccept invite: GKInvite) {
guard let viewController = GKMatchmakerViewController(invite: invite) else {
return
}
viewController.matchmakerDelegate = self
present(viewController)
}
But after presenting the view controller with GKMatchmakerViewController(invite:)
, nothing else happens. I would expect matchmakerViewController(_:didFind:)
to be called, or how would I get an instance of GKMatch
?
Here is the code I use to reproduce the issue, and below the reproduction steps.
- Run the attached project on an iPad and a Mac simultaneously.
- On both devices, tap the ship to connect to GameCenter.
- Create an automatched match by tapping the rightmost icon on both devices.
- When the two devices are matched, on iPad close the dialog and tap on the ship to disconnect from GameCenter.
- Wait some time until the Mac detects the disconnect and automatically sends an invitation to join again.
- When the notification arrives on the iPad, tap it, then tap the ship to connect to GameCenter again. The iPad receives the call
player(_:didAccept:)
, but nothing else, so there’s no way to get aGKMatch
instance again.