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