GKTurnBasedMatch gets data

I'm trying to implement a step-by-step application, and there is no problem sending rotation data, but I don’t see a way to get the data automatically. So far I have learned so much:

  • There is a GKTurnBasedEventHandlerDelegate -protocol. It is easy to implement, but where do I set this object to be a delegate of what it should be a delegate? He is not a delegate of GKTurnBasedMatch or GKTurnBasedMatchmakerViewController , or GKMatchMaker .

  • There is also a GKTurnBasedMatch method called loadMatchDataWithCompletionhandler , but as I understand it, it is called only once when you have a feeling that the match needs to be updated. How do I know if it should be updated? Should I run this function every second or so?

Thanks in advance.

UPDATE: I set [GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate as a static instance implementing GKTurnBasedEventHandlerDelegate . It has never been called.

+3
source share
1 answer

You install it with the instruction below, it becomes the delegate of the shared instance:

 [[GKTurnBasedEventHandler sharedTurnBasedEventHandler] setDelegate:self]; 

You do not need to call loadMatchDataWithCompletionhandler manually when one of the participants calls endTurnWithMatchData , all other participants will be notified via the GKTurnBasedEventHandler delegation method:

 -(void) handleTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive 

This is where you need to update the interface. Beware that the simulator does not support the GKTurnBasedEventHandler delegate GKTurnBasedEventHandler , they are called only on real devices.

+3
source

All Articles