I'm new to Swift and Mac/iOs programming in general. I'm running this sample on a Macbook Pro with BLE support and with Bluetooth turned on, using Xcode 7.3.
import Foundation
import CoreBluetooth
func printState(state: CBCentralManagerState) {
switch state {
case CBCentralManagerState.PoweredOn:
print("Powered on")
case CBCentralManagerState.PoweredOff:
print("Powered off")
case CBCentralManagerState.Resetting:
print("Resetting")
case CBCentralManagerState.Unauthorized:
print("Unauthorized")
case CBCentralManagerState.Unknown:
print("Unknown")
default:
print ("Unsupported")
}
}
var myCentralManager = CBCentralManager(delegate:nil, queue:nil)
while true {
printState(myCentralManager.state)
sleep(1)
}
The code prints out "Unknown" over and over, even after many minutes. I've also tried setting up a delegate but the didUpdateState callback doesn't called. I've also tried to run this from the command line and Swift interpreter and get the same result.
I must be missing something very basic. How can I get it to report that the CBCentralManager is powered on?