Possible Duplicate:
Send NSString via Game Center
i have been working on this for two days now and not been getting anywhere, i was hoping someone could shed some light on the problem.
1) i have an NSMUtableArray
2) each element within the array is serialised through [encoder encodeObject: myArray]; and the result is returned and assigned to a struct “MessageMove” called “cards” (of type NSData *)
MessageMove message;
….
typedef struct
{
Message message;
NSData *cards;
} MessageMove;
3) Now that the cards have been converted to type NSData i now want to do the same for the struct itself, i call
NSData *data = [NSData dataWithBytes:&message length:sizeof(message)];
4) Finally i send the data to the other player as follows
BOOL success = [[GCHelper sharedInstance].match sendDataToAllPlayers:data withDataMode:GKMatchSendDataReliable error:&error];
the trouble lies with the receiving end not getting any of the Cards data at all (MessageMove->cards). This is probably because the NSData * is not being sent remotely but rather only the pointer to it.
Does anyone know how i can send the actual data? I have been scratching my head all day at this problem and don’t know how i can overcome it
many thanks
Make
MessageMovean Objective-C class that conforms to theNSCodingprotocol. Then serialise it to anNSDataobject, and deserialise it on the other end. For more details, see my earlier answer.