当我运行我的代码并在我的MacbookPro上打开/关闭蓝牙时,状态总是4
,它对应于PoweredOff
状态。
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")
}
}
}
我知道蓝牙实际上是开着的,因为我已经能把它和我的手机配对了。
发布于 2014-11-05 18:28:17
回答我自己的问题。
事实证明,CoreBluetooth
只适用于蓝牙4.0:
核心蓝牙框架是蓝牙4.0规范(来源)的抽象
要了解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
不会为我工作。
有趣的是,开关语句并没有给我提供.Unsupported
的情况。
编辑:
在用蓝牙4在较新的mac上测试了完全相同的代码之后,状态变成了.PoweredOn
。
https://stackoverflow.com/questions/26764147
复制相似问题