I have a question regarding sending and receiving data through Game Center when playing a multi-player game on iOS.
In my game after I matchmake two people, the game is taken to the Game Screen where the user can start playing.
Because the two devices do not load the game screen at the same time (for network reasons), the viewDidLoad function in my first device sometimes will already have completed by the time the second device has loaded the screen.
What this means is say for example in the viewDidLoad I send through my local player alias to my slower device, as the slower device is still loading by the time the faster device is doing so, when the screen loads, my faster device receives the slower devices player alias, but not vice versa.
Therefore, is there any easy way for one device to detect when the other device has loaded, and push through any relevant code from there?
First of all, you should only send messages once the connection has been established. You can detect this in the
match: player: didChangeState:method of your delegate by waiting for theGKPlayerStateConnectedstate. If you send any message after this event occurred, it should arrive.Otherwise, there may be concerns with your design. Your delegate should be able to interpret and use any message that comes in. If you are exchanging player aliases and really need to know them when starting the game, you should wait for the alias to come in as a trigger, or come up with an even more elaborate handshake protocol.
So, one simple recipe would be to
GKPlayerStateConnectedmessage.