Today we take a quick detour to look at something specific to Apple devices.
You Can’t Handle The API!
iOS has always been the most “locked-down” mobile platform and one of its restrictions has been a lack of support for developers to work with Bluetooth Classic devices. “But wait, 32feet.NET has support for Bluetooth Classic on iOS!” comes a carefully planted cry from the audience. The truth is there are certain scenarios where you can talk to Bluetooth Classic but terms and conditions apply.
As with wired accessories, Apple insists that Bluetooth devices require MFi (Made for iOS but originally Made for iPod) certification. This requires a different presentation of the service rather than just reporting Serial Port service or similar. MFi devices require a special chip to support it, making it quite an involved process for a manufacturer to implement. Therefore, on the small number of devices which support this there is often a mechanism to switch modes between iOS and everything else.
The iOS SDK has a special API specifically for these devices called External Accessory framework and this supports both Bluetooth and wired accessories. As part of the certification each vendor is assigned a specific protocol identifier which is a text string. For example for Zebra thermal printers it is “com.zebra.rawport”.
32feet.NET is able to implement both the BluetoothDevicePicker and the BluetoothClient using the External Accessory framework on the basis that each device exports only a single service and so maps whatever service UUID (99% of the time for Serial Port Profile) you request to the first available protocol on the device. If anyone knows of a device supporting multiple protocols I’d be very interested to hear about it. From there on in it’s a stream interface so just requires some wrapping to expose a standard .NET stream.
The key differences between working with iOS and other platforms are:-
- No device discovery – you have to present the picker to the user or get the previously paired devices.
- No access to the Bluetooth address of the device.
- Only a subset of devices are supported and may have to be placed in a specific mode.
However, if you are aware of these limitations you can still use 32feet.NET to write cross-platform code despite the underlying implementation.
Luckily the support for Bluetooth Low Energy is a lot more open (although there are still limitations) and there are no specific device limitations. 32feet.NET’s Bluetooth Low Energy library supports iOS, watchOS, tvOS and macOS – they all share the same CoreBluetooth API (with just a few small differences!). We’ll look at Bluetooth Low Energy later in this series.