GKTurnBasedMatch如何接受新的匹配邀请

时间:2016-06-11 00:35:07

标签: ios swift gamekit gkturnbasedmatch

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

我看到 expectedState =“邀请”foundState =“有效”异常

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 method

开始
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 enter image description here

玩家2在加载来自玩家1的比赛之前 enter image description here

1 个答案:

答案 0 :(得分:0)

我回答了有关完全以编程方式处理回合制匹配here的问题,即使页面上的问题是关于使用标准GKTurnBasedMatchMakerViewController,我相信该帖子中的信息可能会有所帮助。

当然,人们想要的是一个名为localPlayerDidAcceptInvitation(...)的简单委托函数。但缺席的是,该链接上提供的信息可能有助于将有效的信息汇总在一起。