Tyler
Tyler

Reputation: 18157

CBCentralManager state is always off

When I run my code, and turn on/off the bluetooth on my MacbookPro, the state is always 4, which corresponds to the PoweredOff state.

import Cocoa
import CoreBluetooth

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, CBCentralManagerDelegate {

    var centralManager = CBCentralManager()

    func applicationDidFinishLaunching(aNotification: NSNotification) {
        centralManager = CBCentralManager(delegate: self, queue: nil)
    }

    func centralManagerDidUpdateState(central: CBCentralManager!) {

        switch central.state {

            case .PoweredOn:
                println(".PoweredOn")

            case .PoweredOff:
                println(".PoweredOff")

            case .Resetting:
                println(".Resetting")

            case .Unauthorized:
                println(".Unauthorized")

            case .Unknown:
                println(".Unknown")

            case .Unsupported:
                println(".Unsupported")
        }
    }
}

I know that the Bluetooth is in-fact on, because I have been able to pair it with my phone.

Upvotes: 3

Views: 1983

Answers (1)

Tyler
Tyler

Reputation: 18157

Answering my own question...

It turns out that CoreBluetooth is only for Bluetooth 4.0:

The Core Bluetooth framework is an abstraction of the Bluetooth 4.0 specification (source)

To find out what bluetooth specification your mac has:

 > About This Mac > More Info... > System Report... > Hardware > Bluetooth

Look for the LMP Version

0x4 = Bluetooth Core Specification 2.1 + EDR
0x6 = Bluetooth Core Specification 4.0

I have LMP version 4, so CoreBluetooth won't work for me I guess.

Its interesting that the switch statement wasn't giving me the .Unsupported case though.


Edit:
After testing the exact same code on a newer mac with bluetooth 4, the state became .PoweredOn.

Upvotes: 3

Related Questions