Robert Spychala

I work at de-de.com

The amazing iOS 5 API nobody talks about

originally appeared on http://www.de-de.com/blog/14177518904-bluetooth

There have been rumblings about some of the new additions to the iOS 5.0 bluetooth stack and hardware in iPhone 4S. ex: [link]

So let’s poke around the Core Bluetooth Framework in the Xcode documentation and see what kinds of new things will be possible with this API.

Some high level benefits of this API are:

Let’s see how a typical CoreBluetooth iOS session might look like.

CBCentralManager *mgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[mgr scanForPeripheralsWithServices:nil options:nil];

If you choose to pass nil instead an array of CBUUIDs, your device will scan the radio waves for any Bluetooth 4.0 LE signal. Note that this is probably not the optimal way to do things since it will use the most battery. Now, if there are Bluetooth 4.0 devices broadcasting in your area, your delegate will get called whenever an advertisement payload is detected.

Note that a Bluetooth 4.0 LE device that has another iPhone (or another client) connected to it will stop broadcasting itself.

- (void)centralManager:(CBCentralManager *)central 
    didDiscoverPeripheral:(CBPeripheral *)peripheral
    advertisementData:(NSDictionary *)advertisementData
    RSSI:(NSNumber *)RSSI {

    ...

}

Quite a number of previously impossible things are now made simple with just the above 2 API calls.

All of the above is just the beginning. The API allows your iPhone to stream data from the service once it is discovered and connected to, etc. Just like the older Bluetooth spec, but simpler. In the spec’s simplicity lies its power.

This is just one thing that is no possible yet (though it would be super cool if they were on Apple’s todo list):

Now we just need to wait for some devices to come out into the market that the iPhone 4S can connect to :)

blog comments powered by Disqus

rss
archive