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

标签 swift types protocols core-bluetooth

我在 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/

相关文章:

swift - 当核心数据中没有找到相关实体时,无法识别的选择器发送到实例

ios - 具有相同原型(prototype)单元的两个 TableView,约束行为不同

arrays - 要求数组是 Swift 协议(protocol)中的最小大小

swift - 类型别名必须声明为公共(public),因为它符合公共(public)协议(protocol)中的要求

xcode - Swift 类型推断不工作 (Xcode 7.1.1)

ios - 处理 RxSwift 重试和错误处理的最佳实践是什么

ios - 如何在 Objective C 中使用从 iOS 9 创建的约束?

java - 如何将不同类型的ArrayList传递给方法?

c++ - 八位字节,四字还是什么?

c# - 类型转换为具有相同属性的另一个