GKTurnBasedMatch接收数据 [英] GKTurnBasedMatch receive data
问题描述
我正在尝试实现基于回合的应用程序,并且发送回合数据没有问题,但是我看不到自动接收数据的方法.到目前为止,我发现了很多:
I am trying to implement a turn-based app, and there is no problem with sending turn data, but I see no way of receiving data automatically. So far, I have found out that much:
-
有一个
GKTurnBasedEventHandlerDelegate
协议.这很容易实现,但是我应该在哪里将该对象设置为必须委托的对象呢?它似乎不是GKTurnBasedMatch
,GKTurnBasedMatchmakerViewController
或GKMatchMaker
的委托.
There is a
GKTurnBasedEventHandlerDelegate
-protocol. It is easy to implement, but where do I set that object to be a delegate of whatever it has to be a delegate of? It does not seem to be a delegate ofGKTurnBasedMatch
, orGKTurnBasedMatchmakerViewController
, orGKMatchMaker
.
还有一种GKTurnBasedMatch
的方法,称为loadMatchDataWithCompletionhandler
,但是据我所知,当您有点直觉认为需要更新比赛时,它只会被调用一次.我怎么知道它必须更新?我是否必须每秒左右触发一次此功能?
There is also a method of GKTurnBasedMatch
which is called loadMatchDataWithCompletionhandler
, but, as far as I understand, it is only called once when you kinda have a gut feeling that the match needs to be updated. How am I to know that it has to be updated? Do I have to fire this function every second or so?
谢谢.
更新:我已经将[GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate
设置为实现GKTurnBasedEventHandlerDelegate
的静态实例.它仍然永远不会被调用.
UPDATE: I have set [GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate
to be a static instance that implements GKTurnBasedEventHandlerDelegate
. It still never gets called.
推荐答案
使用以下语句设置它,它将成为共享实例的委托:
You set it with below statement, it becomes the delegate of a shared instance:
[[GKTurnBasedEventHandler sharedTurnBasedEventHandler] setDelegate:self];
您实际上不需要手动呼叫loadMatchDataWithCompletionhandler
,当其中一位参与者呼叫endTurnWithMatchData
时,所有其他参与者都将通过GKTurnBasedEventHandler
委托方法得到通知:
You do not need to call loadMatchDataWithCompletionhandler
manually actually, when one of the participants call endTurnWithMatchData
all other participants will be notified through GKTurnBasedEventHandler
delegate method:
-(void) handleTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive
那是您需要更新UI的地方.请注意,模拟器不支持GKTurnBasedEventHandler
委托方法,它们只会在实际设备中被调用.
That's where you need to update UI. Beware that simulator does not support GKTurnBasedEventHandler
delegate methods, they only get called in actual devices.
这篇关于GKTurnBasedMatch接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!