Sending Data

Connecting to a new peer is only the first step in implementing a functional peer-to-peer networking app. After connecting to a new peer, you will want to send that peer some data. Sending data using Game Kit is extremely easy. Take a look at the following code snippet:

[mySession sendDataToAllPeers:messageData withDataMode:GKSendDataReliable error:&error];

The first part of this method is a pointer to the session that was returned as part of connecting to a new peer. In the preceding example the data is being sent to all connected peers. There is an alternative method, sendData:toPeers:withDataMode:error:, if you wanted to send data to only a specific peer. The next part of the code snippet is an argument ...

Get iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.