USING THE GAME KIT FRAMEWORK

One of the neat features available in the iOS SDK is the Game Kit framework, which contains APIs that enable communications over a Bluetooth network. You can use these APIs to create peer-to-peer games and applications with ease. Unlike other mobile platforms, using Bluetooth as a communication channel in the iOS is much easier than you might expect.

In this section, you will learn how to build a simple application that enables two iOS devices to communicate with each other.

Searching for Peer Devices

Before any exchanges of data can take place, the first step to Bluetooth communication is for the devices to locate each other. The following Try It Out shows you how to use the Game Kit framework to locate your Bluetooth peer.

TRY IT OUT: Looking for Peer Devices

image

  1. Using Xcode, create a new Single View Application (iPhone) project and name it Bluetooth. You need to use the project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Add the GameKit.framework to your project (see Figure 17-1).
  3. Select the BluetoothViewController.xib file to edit it in Interface Builder. As shown in Figure 17-2, add the following views to the View window:
    • Text Field
    • Round Rect buttons (name them Send, Connect, and Disconnect)

    FIGURE 17-1

    FIGURE 17-2

  4. In the BluetoothViewController.h file, add the following statements ...

Get Beginning iOS 5 Application Development 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.