GameCenter - Receive Multiple Bits of Data?
-
10-10-2019 - |
Question
So I have sending and receiving data in GameCenter on my iphone working well, but when you receive data you get 'data' from the method. How do you know whether this is for example a score or health points?
How do you differentiate what data is received?
Thanks.
Solution
As explained by Apple's docs...
'Your message format should include a way to differentiate between different kinds of messages. For example, you might create an enumerated type that identifies different kinds of messages. The first bytes in every message would start with this enumerated type.'
OTHER TIPS
Look at SessionManager.m in the GKRocket example in the docs. Especially the implementations of
-(void) sendPacket:(NSData*)data ofType:(PacketType)type
and
- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow