You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GKTurnBasedMatch:当前参与者未触发receivedExchangeReplies方法求助

GameKit player(_:receivedExchangeReplies:forCompletedExchange:for:) only called for exchange initiator, not current turn holder

I've been stuck on this issue for weeks and haven't found any solutions online. According to source code comments, official docs, and various resources, the ReceivedExchangeReplies(GKPlayer, GKTurnBasedExchangeReply[], GKTurnBasedExchange, GKTurnBasedMatch) method (I'm using its Swift equivalent below) should be called for both the exchange initiator and the current participant once all recipients of an exchange have replied or the exchange has timed out.

But in my app, this method only gets triggered for the exchange initiator—it never fires for the current turn holder. The turn holder is supposed to merge and process changes after the exchange completes, but without this notification, I can't move forward with development. My temporary workaround is to manually send an extra exchange to notify the turn holder, but this means they end up merging changes blindly without confirming the exchange is actually complete.

Authentication Handler (working correctly)

func authenticateLocalPlayer() { 
    let localPlayer: GKLocalPlayer = GKLocalPlayer.localPlayer() 
    localPlayer.authenticateHandler = {(viewController, error) -> Void in 
        if let viewController = viewController { 
            self.underlyingViewController.present(viewController, animated: true, completion: nil) 
        } else if localPlayer.isAuthenticated { 
            self.gamecenterEnabled = true 
            localPlayer.unregisterAllListeners() 
            localPlayer.register(self) 
            self.findBattleMatch() 
        } else { 
            self.gamecenterEnabled = false 
            print(error as Any) 
        } 
    } 
}

Code to send exchange request

currentMatch.sendExchange(to: [nextParticipant], 
                          data: GameState.encodeStruct(structToEncode: structToSend), 
                          localizableMessageKey: messageKey, 
                          arguments: ["X","Y"], 
                          timeout: TimeInterval(timeOutDebug), 
                          completionHandler: {(exchangeReq: GKTurnBasedExchange?, error: Error?) -> Void in 
    if error == nil { 
        print("Operation successful") 
    } else { 
        print(error as Any) 
    } 
})

Code to reply to exchange

exchange.reply(withLocalizableMessageKey: exchange.message!, 
               arguments: ["XY","Y"], 
               data: GameState.encodeStruct(structToEncode: exchangeReply), 
               completionHandler: {(error: Error?) -> Void in 
    if error == nil { 
        print("ExchangeReply sent successfully") 
    } else { 
        print(error as Any) 
    } 
})

The callback method that's not firing for the turn holder

func player(_ player: GKPlayer, receivedExchangeReplies replies: [GKTurnBasedExchangeReply], forCompletedExchange exchange: GKTurnBasedExchange, for match: GKTurnBasedMatch){ 
    print("Exchange was completed, turnholder and Exchange-initiator should act on that in following code.") 
    // ... my processing code ...
}

This is the Swift version of the Objective-C method referenced in docs.

I initially thought maybe the exchange was completing too quickly for the listener to catch it, so I tried adding a delay before replying—but either the exchange object becomes nil or I get a communication error (something like "message was sent over different proxy error").

My core question: Is the current turn holder actually supposed to receive this callback when an exchange completes, or have the rules changed? Any help would be massively appreciated.

内容的提问来源于stack exchange,提问作者Skeltek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:21:40