使用 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
}
}