gpt4 book ai didi

swift - 符合 'CBCentralManagerDelegate'协议(protocol)

转载 作者:行者123 更新时间:2023-11-30 10:43:13 29 4
gpt4 key购买 nike

我在 project-Swift.h 文件中收到名为“CBCentralManagerDelegate”的 No 类型或协议(protocol)。不知道我在这里哪里出错了。我认为这与 swift.h 有关,但我是 CoreBluetooth 的新手,所以可能是这样

@objcMembers
class KestrelDeviceConnect: NSObject, CBCentralManagerDelegate, CBPeripheralManagerDelegate {

var manager:CBCentralManager!
var peripheral:CBPeripheral!
let serviceCBUUID = CBUUID(string: "0x181A")
var FieldSummaryModalLoaded = false

override init() {
super.init()
manager = CBCentralManager(delegate: self, queue: nil)
}

@objc func fieldSummaryReportMCLoaded(){
FieldSummaryModalLoaded = true
}
@objc func fieldSummaryReportMCChanged() {
FieldSummaryModalLoaded = false
}


func getWeatherReading() -> WeatherThirdPartyReadings {

var weatherReading = WeatherThirdPartyReadings(temperature: 0.00, speed: 0.00, direction: 0.00, observationTime: 0.00, isSummaryLoaded: false)

manager.scanForPeripherals(withServices: nil)
return weatherReading
}

func centralManagerDidUpdateState(_ central : CBCentralManager){

switch central.state {
case .poweredOff:
print("off")

case .poweredOn:
print("on")
manager.scanForPeripherals(withServices: [serviceCBUUID])
case .resetting:
print("resetting")

case .unauthorized:
print("unauthorized")
case .unknown:
print("unknown")

case .unsupported:
print("unsupported")

default:
break
}
}
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {

}

}

最佳答案

不得不#import <CoreBluetooth/CoreBluetooth.h>在桥接 header 中

关于swift - 符合 'CBCentralManagerDelegate'协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56348946/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com