3
当我运行我的代码并打开/关闭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")
}
}
}
我知道蓝牙是事实上的,因为我已经能够将它与手机配对。
如果你没有得到你的机器上不支持的状态,那很可能是一个错误。 – allprog 2014-11-06 22:20:36