【问题标题】:Conform to 'CBCentralManagerDelegate' protocol符合 'CBCentralManagerDelegate' 协议
【发布时间】:2019-10-14 09:07:12
【问题描述】:

我在 project-Swift.h 文件中得到一个名为“CBCentralManagerDelegate”的 No 类型或协议。不知道我哪里出错了。我认为这与 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) {

    }

}

【问题讨论】:

    标签: swift types protocols core-bluetooth


    【解决方案1】:

    必须在桥接头中#import <CoreBluetooth/CoreBluetooth.h>

    【讨论】:

      猜你喜欢
      • 2017-07-22
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多