我正在尝试实施BLEHandler。
这是我的代码:
import CoreBluetooth
class BLEHandler : NSObject, CBCentralManagerDelegate {
override init() {
super.init()
}
func cenrealManagerDidUpdateState(central: CBCentralManager!)
{
switch (central.state)
{
case . unsupported:
print("BLE is unsupported")
case.unauthorized:
print("BLE is unauthorised")
case.unknown:
print("BLE is unknown")
case.resetting:
print("BLE is resetting")
case.poweredOff:
print("BLE is powered off")
case.poweredOn:
print("BLE is powered on")
default:
print("BLE default")
}
}
}
我收到错误: “类型'BLEHandler'不符合协议'CBCentralManagerDelegate'”
我有'centralManagerDidUpdateState'方法,所以我不知道我错过了什么等。
答案 0 :(得分:3)
方法名称拼写错误。不是cenrealManagerDidUpdateState
,应该是centralManagerDidUpdateState
试试......
func centralManagerDidUpdateState(_ central: CBCentralManager)
{
}