没有名为“ CBCentralManagerDelegate”的类型或协议

时间:2019-05-28 17:21:43

标签: ios swift core-bluetooth

我正在尝试实现CoreBluetooth,但是在此行的project-Swift.h文件中得到了此错误。我必须遵守任何协议吗?我对CoreBluetooth还是很陌生,所以我不确定是否可以正确使用

@interface KestrelDeviceConnect : NSObject <CBCentralManagerDelegate>

这是我的课程

import Foundation
import CoreBluetooth

class KestrelDeviceConnect: NSObject, CBCentralManagerDelegate{

    var manager:CBCentralManager!
    var peripheral:CBPeripheral!

    func getData() -> WeatherThirdPartyReadings {
        manager = CBCentralManager(delegate: self, queue: nil)

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




        return weatherReading
    }

    func centralManagerDidUpdateState(_ central : CBCentralManager){

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

            case .poweredOn:
                print("on")
                manager.scanForPeripherals(withServices: nil, options: nil)

            case .resetting:
                print("resetting")

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

            case .unsupported:
                print("unsupported")

            default:
                break
        }
    }

}

0 个答案:

没有答案
相关问题