1

使用 GameKit 的标准用户界面以编程方式接受比赛邀请的正确方法是什么?

我看到了一个expectedState="Invited" foundState="Active"异常

Optional(Error Domain=GKErrorDomain Code=22 
"The requested operation could not be completed because the specified participant is invalid." 
UserInfo={GKServerStatusCode=5097, 
NSLocalizedDescription=The requested operation could not be completed because the specified participant is invalid., 
NSUnderlyingError=0x14fa2cf70 {
Error Domain=GKServerErrorDomain Code=5097 "status = 5097, 
Unexpected slot state expectedState="Invited" foundState="Active"

在以下情况下会发生异常:
玩家 1 - 与玩家 2 创建新匹配
玩家 1 - 迈出第一步
玩家 2 - 尝试从基于回合的匹配中加载数据并接受匹配邀请。

我正在使用 iOs 的标准用户界面进行配对。GKTurnBasedMatchmakerViewController

请求新的比赛

let matchRequest = GKMatchRequest()
matchRequest.minPlayers = 2
matchRequest.maxPlayers = 2
matchRequest.defaultNumberOfPlayers = 2
matchRequest.inviteMessage = "Play BoxTheDots with me"
matchRequest.recipientResponseHandler = self.matchMaker?.recipientResponse

let matchView = GKTurnBasedMatchmakerViewController(matchRequest: matchRequest)
self.presentViewController(matchView, animated: true, completion: nil)
matchView.turnBasedMatchmakerDelegate = self.matchMaker?.matchViewController

我正在以编程方式接受比赛邀请,这导致并打印了错误。

代码流从GKTurnBasedMatchmakerViewControllerDelegate didFindMatch 方法开始

func turnBasedMatchmakerViewController(viewController: GKTurnBasedMatchmakerViewController, didFindMatch match: GKTurnBasedMatch){
    match.loadMatchDataWithCompletionHandler(self.matchDataLoaded)    
    match.acceptInviteWithCompletionHandler(self.acceptInvite)
}

private func acceptInvite(match:GKTurnBasedMatch?, error:NSError?){
    guard error == nil else {
        LogUtil.log(.CRITICAL, sub: .ERROR, o: self, method: method, msg: "could not accept match invite. \(error)")
        return
    }
}

玩家 1 完成第一回合后 在此处输入图像描述

玩家 2 在从玩家 1 加载比赛之前 在此处输入图像描述

4

1 回答 1

0

我在这里回答了一个关于完全以编程方式处理的回合制比赛的问题,尽管页面上的问题是关于使用标准的GKTurnBasedMatchMakerViewController,但我相信该帖子中的信息可能会有所帮助。

当然,人们想要的是一个简单的委托函数,名为localPlayerDidAcceptInvitation(...). 但如果没有这一点,该链接上提供的信息可能有助于将有效的东西组合在一起。

于 2017-03-07T20:13:27.423 回答