CBCentralManager状态始终关闭
问题描述:
当我运行我的代码并打开/关闭MacbookPro上的蓝牙时,状态始终为4
,对应于PoweredOff
状态。CBCentralManager状态始终关闭
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")
}
}
}
我知道蓝牙是事实上的,因为我已经能够将它与手机配对。
答
回答我的问题...
事实证明,CoreBluetooth
仅适用于蓝牙4.0:
的抽象核心蓝牙框架是蓝牙4.0规范(source)
要了解您的mac有哪些蓝牙规格:
> About This Mac > More Info... > System Report... > Hardware > Bluetooth
外观为LMP Version
0x4 = Bluetooth Core Specification 2.1 + EDR
0x6 = Bluetooth Core Specification 4.0
我有LMP版本4,所以CoreBluetooth
不会为我工作,我猜。
有趣的是,switch语句并没有给我.Unsupported
的情况。
编辑:
与蓝牙4.0测试在一个较新的MAC完全相同的代码之后,状态变成.PoweredOn
。
如果你没有得到你的机器上不支持的状态,那很可能是一个错误。 – allprog 2014-11-06 22:20:36