Getting around iOS9 CoreBluetooth omissions with Swift Extensions

Getting around iOS9 CoreBluetooth omissions with Swift Extensions

Getting around iOS9 CoreBluetooth omissions with Swift Extensions

While working on the BLEvolve app (http://blevolve.com), the CoreBluetooth project I was working on began crashing after updating the OS to iOS9.  The bluetooth device vendors’ APIs used two properties:

  • CBPeripheral.isConnected – to query whether a Bluetooth device connected through CoreBluetooth was currently connected
  • CBPeripheral.UUID – to query the “UUID” a.k.a. universally unique identifier of the Bluetooth device

Well OK then.  I had an Objective-C SDK library that made extensive use of these properties (snfsdk) that I didn’t have the source code to...  Only the framework libraries and headers.  What to do?  The most obvious solution is to add the properties back in.  Using the recommended replacement properties, just aliased with the old names.  The following gist, “CBPeripheralExtensions.swift” does exactly that.

Extending code that you don’t fully control is a very powerful function. Really glad both Objective-C and Swift have this capability, it has come in handy quite a few times in my projects.

Leave a Reply

Your email address will not be published. Required fields are marked *