Swift 5.x iOS 14
Trying to Get GameKit Matchmaking, and almost there...but... my match seems to fail with this error message?
Run GameKit on two real devices logged into different IDs. I get the gameKit matching interface up. Find my peer, and invite? and get this error message ...
2021-08-26 16:29:01.361416+0200 Mutate[18060:12891141] [AXRuntimeCommon] Unknown client: FAQ 2021-08-26 16:29:01.705773+0200 FAQ[18060:12891041] [Match] Error sending dictionary { bundleID = "ch.cqd.FAQ"; bundleVersion = 1; isDevelopmentVersion = 1; message = 0; platform = 1; shortBundleVersion = "1.0"; } to deviceID: 076731E70C32E9C1, error = Error Domain=GKDiscoveryManager Code=-1 "Peer does not exist" UserInfo={NSLocalizedDescription=Peer does not exist}
The invited one starts playing, but the one inviting get stuck waiting for a response? What am I missing?
class SimpleViewController: UIViewController {
and
extension SimpleViewController: GKMatchmakerViewControllerDelegate, GKMatchDelegate, UINavigationControllerDelegate, GKGameCenterControllerDelegate, GKLocalPlayerListener, GKInviteEventListener, GKTurnBasedEventListener {
Plus their methods...
Here is the code ...
class SimpleViewController: UIViewController {
let minPlayers = 2
let maxPlayers = 4
override func viewDidLoad() {
super.viewDidLoad()
GKLocalPlayer.local.authenticateHandler = { [self] gcAuthVC, error in
if GKLocalPlayer.local.isAuthenticated {
GKLocalPlayer.local.register(self)
print("Authenticated to Game Center!")
let request = GKMatchRequest()
request.minPlayers = minPlayers
request.maxPlayers = maxPlayers
request.inviteMessage = "Mutant Anyone?"
let vc = GKMatchmakerViewController(matchRequest: request)
vc!.delegate = self
present(vc!, animated: true)
This bit I am sure works... but
extension SimpleViewController: GKMatchmakerViewControllerDelegate, GKMatchDelegate, UINavigationControllerDelegate, GKGameCenterControllerDelegate, GKLocalPlayerListener, GKInviteEventListener, GKTurnBasedEventListener {
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
self.dismiss(animated: true)
match.delegate = self
print("matchmakerViewController ")
}
func player(_ player: GKPlayer, didAccept invite: GKInvite) {
self.dismiss(animated: true, completion: {
print("player ",invite)
})
}
func matchmakerViewController(_ viewController: GKMatchmakerViewController, hostedPlayerDidAccept player: GKPlayer) {
print("matchmakerViewController")
self.dismiss(animated: true, completion: {
print("player ",player)
})
}
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFindHostedPlayers players: [GKPlayer]) {
print("matchmakerViewController")
self.dismiss(animated: true, completion: {
print("player ",players)
})
}
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
self.dismiss(animated: true)
print("matchmakerViewControllerWasCancelled")
}
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
print("Matchmaker vc did fail with error: \(error.localizedDescription).")
}
}
I suspect the mistake is in here?