Swift Game Center多人游戏-主机取消了连接

时间:2018-08-06 12:11:31

标签: ios swift

我在完成与比赛的连接时遇到问题。我能够进行身份验证,然后显示MatchmakerViewController。我正在使用Xcode模拟器和真实设备进行测试。设备找到彼此后,媒人视图控制器将被关闭。正是在这一点上,它立即收到主机取消的连接。以下是我目前拥有的Game Center代码。任何帮助和/或想法将不胜感激。

class NewGCHelper: NSObject, GKGameCenterControllerDelegate, GKMatchmakerViewControllerDelegate, GKMatchDelegate {

    var scene: SKScene?
    var localPlayer: GKLocalPlayer?
    var match: GKMatch?
    var matchRequest: GKMatchRequest?


    init(scene: SKScene) {
        self.scene = scene
        super.init()
        setup()

    }

    func setup() {

    }

    //MARK: START ONLINE GAME FUNCTION
    func startMatch() {
        let request = GKMatchRequest()
        request.defaultNumberOfPlayers = 2
        request.minPlayers = 2
        request.maxPlayers = 2
        matchRequest = request

        let mmvc = GKMatchmakerViewController(matchRequest: matchRequest!)
        mmvc?.matchmakerDelegate = self
        let vc = self.scene?.view?.window?.rootViewController
        vc?.present(mmvc!, animated: true, completion: nil)

    }

    //MARK: AUTHENTICATE LOCAL PLAYER FUNCTION
    func authenticateLocalPlayer(){
        localPlayer = GKLocalPlayer.localPlayer()
        //localPlayer.register(self)
        localPlayer?.authenticateHandler = {(viewController, error) -> Void in
            if (viewController != nil) {
                print("Not signed in. Authenticating now")
                let vc = self.scene?.view?.window?.rootViewController
                vc?.present(viewController!, animated: true, completion: nil)
            } else if (self.localPlayer?.isAuthenticated == true) {
                print("Local Player is Authenticated")
            } else {
                print("Error in authenticating")
            }
        }
    }

    // MARK: - GCVC FUNCTIONS
    func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) {
        print("*** GAME CENTER AUTHENTICATION HAS BEEN DISMISSED ***")
        gameCenterViewController.dismiss(animated: true, completion: nil)
    }

    //MARK: MATCH MAKER VIEW CONTROLLER FUNCTIONS
    func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
        print("Match Maker Was Cancelled")
        viewController.dismiss(animated: true, completion: nil)
    }

    func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
        print("Match Maker Faile with Error: \(error.localizedDescription)")
        viewController.dismiss(animated: true, completion: nil)
    }

    func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
        print("Match Maker Did Find Match \(match.players)")
        self.match = match
        self.match?.delegate = self

        if match.expectedPlayerCount == 0 {
            viewController.dismiss(animated: true, completion: {

            })
        }
    }
}

在这里,视图控制器被列为各种错误

本地播放器已通过身份验证 *触摸在线按钮*

  

2018-08-06 07:47:36.107014-0400 Ninepenny [37305:1177056] [日志] [错误]   gckSessionCheckPendingConnections:1438   gckSessionCheckPendingConnections:iICEChecksLeft = 0,   iUnconnectedNodeCount = 0,iDDsExpected = 1 2018-08-06   07:47:36.123056-0400 Ninepenny [37305:1176942] [日志] [错误]   ICEStopConnectivityCheck:2688 ICEStopConnectivityCheck()未找到ICE   检查带有呼叫ID(1150981164)2018-08-06 07:47:36.130108-0400   Ninepenny [37305:1176942] [log] [ERROR]   gckSessionCheckPendingConnections:1438   gckSessionCheckPendingConnections:iICEChecksLeft = 0,   iUnconnectedNodeCount = 0,iDDsExpected = 0匹配制造商没有找到匹配项   [(playerID:G:16024758149别名:Bdubs.93   名称:“‪Bdubs.93‬”状态:(空))] 2018-08-06 07:47:39.682225-0400   Ninepenny [37305:1176388] [错误]扩展请求被取消   错误:错误域= NSExtensionErrorDomain代码= -2“扩展名   被主机取消。” UserInfo = {NSLocalizedDescription =扩展名   被主机取消。}

0 个答案:

没有答案