Creating a peer-to-peer bluetooth network
In this recipe, we will create a peer-to-peer bluetooth network, which we will use to exchange text messages. To create a bluetooth peer-to-peer network, we will use Apple's Game Kit framework. So, we will need to add the Gamekit framework to our project.
The downloadable code for this project creates a peer-to-peer network that is used to exchange text messages. Each individual message that is sent over the bluetooth network can have a maximum size of 90 KB. If the data that we are sending is greater then 90 KB, we will need to break the data apart and send it as multiple messages.
We will be implementing the GKPeerPickerController
and GKSession
delegate methods. The GKPeerPickerController
method provides a standard user interface, which allows one iOS device to connect to another iOS device. Once the two devices are connected, a GKSession
object is returned. The GKSession
object is used to send and receive data between the two peers.
When the peer...