如何在SwiftUI中呈现Game Center配对视图控制器?

时间:2020-05-12 03:06:19

标签: swift swiftui game-center

我正在与SwiftUI和Game Center一起创建多人游戏。用播放器和邀请消息的数量初始化它后,我无法呈现GKMatchmakerViewController。我尝试使用按钮调用我的presentMatchmaker()函数,但这不起作用。任何帮助深表感谢!

func presentMatchmaker() {
        guard GKLocalPlayer.local.isAuthenticated else {
            return
        }
        let request = GKMatchRequest()
        request.minPlayers = 2
        request.maxPlayers = 7

        request.inviteMessage = "You have been challenged..."

        guard let vco = GKMatchmakerViewController(matchRequest: request) else {
            return
        }
        self.ViewController?.present(vco, animated:true)
}

0 个答案:

没有答案