The amazing iOS 5 API nobody talks about
By @robspychala
(discussion on HN)
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:
- Bluetooth 4.0 LE does not require pairing. So if a TV or another device that you’ve never seen before is broadcasting, you can see its signal and connect to it without having to go to the Settings app.
- Uses less power.
- Apps can be woken up and become active when sent signals via the CoreBluetooth API.
- If another app is using a Bluetooth 4.0 LE device, your app will be able to use it as well. A super awesome use case for this would be that heartbeat monitor you got. Your 3rd party social network app will also be able to use the connection as well!
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.
- Billboards would be able to broadcast coupons to nearby patrons - no cell reception needed.
- A jukebox might advertise the song that’s currently playing with a link to purchase
- Your car could broadcast its stats so that when you pull into a gas station the service mechanics will know whether you need an oil change.
- Your company badge might broadcast your email address so that connecting at business events becomes even easier.
- Your TV could broadcast the link to the current TV channel’s website.
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 not possible yet (though it would be super cool if they were on Apple’s todo list):
- iPhone to iPhone CoreBluetooth communication
Now we just need to wait for some devices to come out into the market that the iPhone 4S can connect to :)
