On May 28, 2010, at 2:25 AM, Philip Vallone wrote: > This is a relative question, which depends on how the data is coming and > going. My question comes from the following situation. Suppose I have a > GKSession that is passing information via Bluetooth. The sender can send any > type of information (NSString, UIImage etc...). The receiver needs to know > how to handle this data. If there is a better way... Then how?
Haven't used GameKit yet, but programs rarely need to send *raw* data. What they usually need to send is some higher-level concept, in your case that could be a "game command". So what you'd usually do is create some NSObject subclass that encapsulates the general API of a "command". You'd in turn create separate subclasses for the individual commands. NSArchiver already knows how to recreate that object, so you'd then just call an -apply method the base class declares but the subclasses implement, and you'd have everything working automatically. The subclass would then take care of unarchiving the expected image resp. string and do with it whatever needs to be done (e.g. update the player avatar with that image, or display the given message from the other user, or apply the movements of a remote user to the local game state. (Of course, there are security/robustness considerations with any network communication to avoid trickery, or just keep cheaters from pretending their player had moved by 6 miles in a split-second and thus wasn't shot, but that's not part of this discussion) -- Uli Kusterer "The Witnesses of TeachText are everywhere..." _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
