Joris Kluivers

I like to build software.

Next Generation Bluetooth 4.0 for iOS / Mac

As of iOS 5 and OS X 10.7 a new framework is available: The CoreBluetooth.framework. This framework enables developers to communicate with a new class of energy efficient Bluetooth devices.

For iOS developers not in the MFi program this is the first time external hardware can be accessed directly from an iPhone, without having to resort to wifi or audio-jack/dock-pin accessories.

No wonder I couldn’t wait to try the Bluetooth Smart heart-rate strap when it finally arrived.

Pictured above is my Wahoo Blue HR heart-rate strap which can connect directly to the iPhone 4s.

Bluetooth Smart

The CoreBluetooth.framework was specifically designed to be used with Bluetooth Smart devices. These devices use a new low energy technology defined in the new Bluetooth 4.0 standard, and will typically be able to operate for a year or more on a single coin-cell battery. However this new technology is not backward compatible with traditional Bluetooth and will not be a magical battery life saver for phones.

All these different versions and compatibilities of Bluetooth can be a bit confusing: I’ve written a longer article in which I try to clarify how Bluetooth 4.0 and Smart devices relate to each other.

Smart Gadgets

The heart rate monitor mentioned above is one of the first available gadgets that actually uses Bluetooth Smart to operate. Because of it’s low energy consumption the technology is ideal for sensor devices like that. Expect a lot of new hardware in health and sports to work with Bluetooth Smart very soon.

A few other examples of current and upcoming Bluetooth Smart uses:

  • Keyboard and trackpads, which will last for years+ instead of weeks on the same pair of batteries. Prototypes are ready.
  • Remote controlling devices. For cameras, tvs and home automation.
  • Quantified self / health (heart rate straps, nike+ technology)
  • A Casio watch: uses low energy to display notifications from your phone for example.
  • The Pebble watch announced BT 4.0 support. It will act as a host device, not really saving battery life but will be able to communicate to heart rate straps for example.

Using CoreBluetooth.framework

The Bluetooth standard describes a number of use-cases called profiles. Each use-case standardizes one or more services a device can implement. A service publishes certain standardized characteristics which applications can read from or write to. So when writing code to interact with a heart rate service a developer can be sure it will work with both a Polar and a Wahoo strap. A full list of standardized Bluetooth low energy services is available on the Bluetooth developer site.

When developing custom or hardware for something not covered by the standard it’s perfectly possible to define a new service and new characteristics.

None of these standardized profiles are currently implemented on iOS on a system wide level. It’s up to the developer to actually write client code to these services in the apps itself. The CoreBluetooth framework provides a general set of classes you can use to implement a profile.

Class table

The Apple developer portal provides several iOS and Mac sample projects that demonstrate the frameworks usage.

Host Hardware

The framework will only work of course when your hardware is actually capable of sending and receiving Bluetooth 4.0 signals. Apple has been shipping Bluetooth 4.0 chips in its recent hardware for a while now. A surprising large number of products already list Bluetooth 4.0 amongst the specifications:

  • Mac Mini
  • MacBook Air
  • iPhone 4s
  • The new iPad

If you own any of that hardware you can start experimenting today.

Hardware teardowns also show that the new AppleTV uses the same wifi/bluetooth chip as found in the new iPad, however Bluetooth 4.0 is not advertised on it’s specifications page. Maybe something that will be enabled in the future.

Android?

Several recent Android phones also shipped with a Bluetooth 4.0 chip. However the Android framework currently doesn’t specify any API’s to use Bluetooth Smart accessories. Several hardware producers like Broadcom and Motorola shipped their own java library, each implementing their own API’s.

So until Google adds API’s to access Bluetooth Smart hardware you’ll have to resort to multiple different API’s to implement functionality that works on all hardware.

Feedback welcome @kluivers on Twitter