i am developing an application in which i will be sending a string to peer(after converting it into NSData object) and also an UIImage again by converting into NSData object.
Now at receiving end i have a receive method
- (void) receiveData:(NSData *)data
fromPeer:(NSString *)peer
inSession:(GKSession *)session
context:(void *)context
My problem is that,same receive method is called every time i send any data,and i have to use image and text data differently.
So how can i know,whether i data that i have received is a NSString object converted into NSData or it’s UIImage data converted into NSData.
please help me.
Take a look at Apple’s
GKRocketsample code, specifically the implementation ofsendData:ofTypeandreceiveData:fromPeer:inSession:context:in SessionManager.m. You will need to define a set of “types” specific to your application and send them as a header in theNSDatapayload, and then read the header on the receiving end to determine how to handle the payload appropriately.