GKTurnBasedMatch receive data

﹥>﹥吖頭↗ 提交于 2019-12-12 14:17:50

问题


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:

  • 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 of GKTurnBasedMatch, or GKTurnBasedMatchmakerViewController, or GKMatchMaker.

  • 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?

Thanks in advance.

UPDATE: I have set [GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate to be a static instance that implements GKTurnBasedEventHandlerDelegate. It still never gets called.


回答1:


You set it with below statement, it becomes the delegate of a shared instance:

[[GKTurnBasedEventHandler sharedTurnBasedEventHandler] setDelegate:self];

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

That's where you need to update UI. Beware that simulator does not support GKTurnBasedEventHandler delegate methods, they only get called in actual devices.



来源:https://stackoverflow.com/questions/15957576/gkturnbasedmatch-receive-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!