首页 > 解决方案 > CoreBluetooth XPC 连接无效错误和 Info.plist 添加

问题描述

override func viewDidLoad() {
    super.viewDidLoad()

    ref = Database.database().reference()
    title = "cry"
    //self.delegate = delegate
    centralManager = CBCentralManager.init(delegate: self, queue: .main)            
}

extension ComposeViewController: CBCentralManagerDelegate, CBPeripheralDelegate {

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    switch central.state {
    case .unknown:
        print("unknoe")
    case .resetting:
        print("reset")
    case .unsupported:
        print("unsupported")
    case .unauthorized:
        print("unauthorized")
    case .poweredOff:
        print("poweredoff")
    case .poweredOn:
        print("poweron")

        centralManager.scanForPeripherals(withServices: [CBUUID.init(string: Service_UUID)])
    }
}


func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
    self.peripheral = peripheral
    print("discover peripheral")


    centralManager.connect(peripheral, options: nil)
}

我收到以下消息:

[CoreBluetooth] XPC 连接无效

我能够收到开机消息,看起来我无法扫描 BLE 设备。我在我的 Infoplist 中为隐私蓝牙外围设备使用描述 NSBluetoothPeripheralUsageDescription 添加了价值,但没有运气。

我尝试连接 ESP32 并向 LCD 屏幕发送消息。ESP32 与我从 App Store 下载的 BLE 扫描仪应用程序配合良好。

标签: swift

解决方案


推荐阅读