GameKit 实时多人游戏通过 GKMatchmakerViewController 连接失败

时间:2021-04-28 22:38:47

标签: swift swiftui connection game-center gamekit

我正在开发基于 GameKit 的应用,并且正在尝试实现多人游戏功能。登录到 GameCenter 并搜索附近的玩家工作正常。玩家似乎连接并且 matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) 被调用(并且被邀请玩家的玩家(_玩家:GKPlayer,didAccept邀请:GKInvite))。但是之后有大量的错误消息以:

开头
[Match] cannot set connecting state for player: GKFriendPlayerInternal(0x281f78000)(*PLAYERDETAILS*), as there is no inviteDelegate set yet. The state might directly change to Ready when we set the inviteDelegate later and call sendQueuedStatesAndPackets.

即使我为 GKMatchmakerViewController 设置了 matchmakerDelegate,也为比赛和 GKLocalPlayerListener 设置了委托。

顺便说一句,该应用程序基于 SwiftUI,并且 GKMatchmakerViewController 是通过 UIViewControllerRepresentable 实现的。这是我的代码的一些部分:

extension GameCenterHelper: GKMatchmakerViewControllerDelegate {
    func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
        currentMatch = nil
        viewController.dismiss(animated: true)
        GKAccessPoint.shared.isActive = true
    }
    
    func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
        viewController.dismiss(animated: true)
        print("Matchmaker vc did fail with error: \(error.localizedDescription).")
        currentMatch = nil
    }
    
    func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
        currentMatch = match
        currentMatch?.delegate = self
                
        viewController.dismiss(animated: true)
        GKAccessPoint.shared.isActive = true
    }
}

extension GameCenterHelper: GKLocalPlayerListener {
    func player(_ player: GKPlayer, didAccept invite: GKInvite) {
        if currentMatchmakerVC != nil {
            currentMatchmakerVC!.dismiss(animated: false, completion: nil)
            self.currentMatchmakerVC!.matchmakerDelegate = nil
            self.currentMatchmakerVC = nil
        }
        
        let delayTime = DispatchTime.now() + .milliseconds(2000)
        
        DispatchQueue.main.asyncAfter(deadline: delayTime) {
            self.currentMatchmakerVC = GKMatchmakerViewController(invite: invite)
            self.currentMatchmakerVC!.matchmakerDelegate = self
            self.rootViewController?.present(self.currentMatchmakerVC!, animated: true) {
                GKAccessPoint.shared.isActive = false
            }
        }
    }
}

extension GameCenterHelper: GKMatchDelegate, GKMatchCombineDelegate {
    func gameDataPublisher() -> AnyPublisher<Data, Never> {
        gameDataSubject.eraseToAnyPublisher()
    }
    
    func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) {
        
    }
    
    func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) {
        guard state == .connected else {
            return
        }
    }
    
    func match(_ match: GKMatch, didFailWithError error: Error?) {
        if let error = error {
            print(error.localizedDescription)
        }
        currentMatch = nil
    }
    
}

更多错误:

2021-04-29 00:05:30.576083+0200 sporty[397:12229] [ViceroyTrace]  [ERROR] OSPFParse_ParsePacketHeader:1083 Bad destination count=0
2021-04-29 00:05:30.579813+0200 sporty[397:12229] [ViceroyTrace]  [ERROR] OSPFParse_ParsePacketHeader:1100 Checksum=42050 doesn't match
2021-04-29 00:05:30.581184+0200 sporty[397:12229] [ViceroyTrace]  [ERROR] OSPFParse_ParsePacketHeader:1083 Bad destination count=0
2021-04-29 00:05:30.581241+0200 sporty[397:12253] [ViceroyTrace]  [ERROR] RemoveNominatedCandidatePair:982 failed with invalid index input: -1, candidate pair count: 4
2021-04-29 00:05:30.581477+0200 sporty[397:12253] [ViceroyTrace]  [ERROR] gckSessionCheckPendingConnections:1440 gckSessionCheckPendingConnections: iICEChecksLeft=0, iUnconnectedNodeCount=0, iDDsExpected=1
2021-04-29 00:05:30.590295+0200 sporty[397:12229] [ViceroyTrace]  [ERROR] ICEStopConnectivityCheck:2747 ICEStopConnectivityCheck() found no ICE check with call id (1411118523)
2021-04-29 00:05:30.590509+0200 sporty[397:12229] [ViceroyTrace]  [ERROR] gckSessionCheckPendingConnections:1440 gckSessionCheckPendingConnections: iICEChecksLeft=0, iUnconnectedNodeCount=0, iDDsExpected=0

0 个答案:

没有答案
相关问题