iosiphoneuikitgame-center

Apple GameKit: unable to handle dismissal of the matchmaker view controller


I have a GKTurnBasedMatchmakerViewController with an associated GKTurnBasedMatchmakerViewControllerDelegate. According to this documentation page, the function turnBasedMatchmakerViewControllerWasCancelled is called when the matchmaker is dismissed (without inviting any players). But I tried dismissing the matchmaker when testing, and this function is never even entered. Am I misunderstanding something about turnBasedMatchmakerViewControllerWasCancelled?

struct MatchmakerView: UIViewControllerRepresentable {    
    func makeUIViewController(context: Context) -> GKTurnBasedMatchmakerViewController {
        let request = // ...
        
        let matchmakerViewController = GKTurnBasedMatchmakerViewController(matchRequest: request)
        
        let matchmakerDelegate = MatchmakerDelegate()
        matchmakerViewController.turnBasedMatchmakerDelegate = matchmakerDelegate
        
        return matchmakerViewController
    }
    
    func updateUIViewController(_ uiViewController: GKTurnBasedMatchmakerViewController, context: Context) {}
}

private class MatchmakerDelegate: NSObject, GKTurnBasedMatchmakerViewControllerDelegate {
    func turnBasedMatchmakerViewControllerWasCancelled(_ viewController: GKTurnBasedMatchmakerViewController) {
        // FIXME: Dismissing the matchmaker does not call this method.
        viewController.dismiss(animated: true)
        print("This print statement is never reached")
    }
}

Solution

  • Resolved: MatchmakerView was missing a makeCoordinator method.