CoreBluetooth Playground

I'm just reading up on the CoreBluetooth module and am trying a simple playground. This is on a late 2012 iMac which according to the system report definitely has BLE support / it is registered under my developer account.

Is there anything additional I need to do to get it running in a playground? At the moment the code is just assigning the delegate and checking the state. It triggers the print in the unsupported case.


class BLEScanner: NSObject, CBCentralManagerDelegate {
  
    var central: CBCentralManager?
  
    override init() {
        super.init()
        let centralQueue = dispatch_queue_create("hi", DISPATCH_QUEUE_SERIAL)
        central = CBCentralManager(delegate: self, queue: centralQueue)
    }

    func centralManagerDidUpdateState(central: CBCentralManager!) {
        switch (central.state) {
            case .PoweredOff: println("Powered off")
            case .Unauthorized: println("Unauthorized")
            case .Unknown: println("Unknown")
            case .PoweredOn: println("Powered on")
            case .Resetting: println("Resetting")
            case .Unsupported: println("Unsupported")
            default: break
        }
    }
}
let ble = BLEScanner()

I'm surprised it even manages that since you don't keep the playground running at the end by running the runloop or using


import XCPlayground
...
XCPSetExecutionShouldContinueIndefinitely(true)


However even when I add those I get unsupported and that's my observation too, CoreBluetooth code returns unsupported in the playground environment, even the OSX playground environment. I wouldn't expect it to work in the iOS playground because CB doesn't work in the iOS sim, I would have expected it to work in the OSX one however .. but it appears not to.


I came here to see if anyone had the same experience, seems you do.


If you compile your code into a quick executable I suspect you'll find it works fine. Annoying however, I wanted to test some CB stuff as I was writing it.


Oddly enough this does work fine in the REPL, but that's not terribly helpful.

CoreBluetooth Playground
 
 
Q