簡體   English   中英

GKTurnBasedMatch如何接受新的匹配邀請

[英]GKTurnBasedMatch how to accept a new match invitation

使用GameKit的標准用戶界面以編程方式接受匹配邀請的正確方法是什么?

我看到expectedState =“邀請”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的比賽之前 在此輸入圖像描述

我回答一個關於全-編程方式處理的回合制比賽的問題在這里 ,即使頁面上的問題是關於使用標准GKTurnBasedMatchMakerViewController ,我相信在該職位的信息可能會有所幫助。

當然,人們想要的是一個名為localPlayerDidAcceptInvitation(...)的簡單委托函數。 但缺席的是,該鏈接上提供的信息可能有助於將有效的東西混合在一起。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM