CoreBluetooth警告:未知错误:迅速移动431

时间:2019-12-19 23:29:28

标签: ios swift bluetooth l2cap

我试图在iOS和Mac OS上打开一个l2capchanel以使用输入流和输出流委托来回发送数据。当我尝试从iPhone上的Mac OS接收数据时,在iOS端出现此错误-[CoreBluetooth]警告:未知错误:431 我找不到与此错误有关的任何东西任何想法怎么回事以及如何解决。这是我正在使用的代码

这是打开l2cap通道的代码

func外设(_外设:CBPeripheral,didOpen通道:CBL2CAPChannel ?,错误:错误?){

    if let error = error {
        print("Error opening l2cap channel - \(error.localizedDescription)")
        return
    }
    guard let channel = channel else {
        return
    }
    self.peripheral=peripheral
    deviceName = peripheral.name       
    print("Opened channel \(channel)")
    self.channel = channel         
    self.channel?.inputStream.delegate = self
    self.channel?.outputStream.delegate = self       
    self.channel?.inputStream.schedule(in: RunLoop.current, forMode: .default)
    self.channel?.outputStream.schedule(in: RunLoop.current, forMode: .default)
    self.channel?.inputStream.open()
    self.channel?.outputStream.open()

}

这就是我的联系方式     func外设(_外设:CBPeripheral,didDiscoverServices错误:错误吗?){         如果让错误=错误{             print(“服务发现错误-(错误)”)             返回         }

    for service in peripheral.services ?? [] {
        print("Discovered service \(service)")
        if service.uuid == serviceID {
            peripheral.discoverCharacteristics(nil, for: service)
        }
    }
}

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
    if let error = error {
        print("Characteristic discovery error - \(error)")
        return
    }

    for characteristic in service.characteristics ?? [] {
        print("Discovered characteristic \(characteristic)")
        if characteristic.uuid ==  PSMID {
            self.characteristic = characteristic
            peripheral.setNotifyValue(true, for: characteristic)
            peripheral.readValue(for: characteristic)
        }
    }
}

func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
    if let error = error {
        print("Characteristic update error - \(error)")
        return
    }

    print("Read characteristic \(characteristic)")

    if let dataValue = characteristic.value, let string = String(data: dataValue, encoding: .utf8), let psm = UInt16(string) {
            print("Opening channel \(psm)")
            self.peripheral?.openL2CAPChannel(psm)
     //   self.peripheral?.

    } else {
        print("Problem decoding PSM")
    }
}

0 个答案:

没有答案