Ios L2CAP通道数据传输

Ios L2CAP通道数据传输,ios,bluetooth-lowenergy,l2cap,Ios,Bluetooth Lowenergy,L2cap,我正在使用面向连接的频道开发BLE应用程序。我使用nordic semiconductor nrf52作为外围设备,使用iPhone 6作为中央管理器 我使用了蓝牙SIG提供的预定义PSM值,即0x0025。 我能够连接到外围设备并成功打开L2CAP通道 我得到以下错误: **[CoreBluetooth]警告:未知错误:436 2018-06-08 10:03:17.532709-0400蓝牙测试[407:62057][CoreBluetooth]**没有已知的与psm 37匹配的对等通道**

我正在使用面向连接的频道开发BLE应用程序。我使用nordic semiconductor nrf52作为外围设备,使用iPhone 6作为中央管理器

我使用了蓝牙SIG提供的预定义PSM值,即0x0025。 我能够连接到外围设备并成功打开L2CAP通道

我得到以下错误:

**[CoreBluetooth]警告:未知错误:436

2018-06-08 10:03:17.532709-0400蓝牙测试[407:62057][CoreBluetooth]**没有已知的与psm 37匹配的对等通道****

请告诉我如何继续,错误代码436是什么意思

下面是我的代码:

   func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        //handling callback when a peripheral is discover
        print("Central Manager PowerOn State Check:\(central.state.rawValue)")
        if (peripheral.name?.contains("Nordic_OTSX") == true)
       {
            print(peripheral.name ??  "no name")
            print("advertisement Data : \(advertisementData) ")
            central.connect(peripheral, options: nil )
            myPeripheral = peripheral
       }
    }


    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)
    {
        print("didConnect\(myPeripheral.debugDescription)")
        myPeripheral.delegate = self
        myPeripheral.discoverServices(nil)
    }
    //if error while making connection
    func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?)
    {
        print("error:\(error.debugDescription)")
    }

    //after opening L2CAP Channel
   func peripheral(_ peripheral: CBPeripheral, didOpen channel: CBL2CAPChannel?, error: Error?)
    {
        print("didOpen")
        print(error.customMirror)
        print(channel!.outputStream.debugDescription)
        print(channel!.inputStream.debugDescription)
        print(channel?.outputStream.hasSpaceAvailable)
    }


    func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)
    {
        print("*******************************************************")

        if ((error) != nil) {
            print("Error discovering services: \(error!.localizedDescription)")
            return
        }

        guard let services = peripheral.services else {
            return
        }
        //We need to discover the all characteristic
        for service in services {

            peripheral.discoverCharacteristics(nil, for: service)
            // bleService = service
        }
        print("Discovered Services: \(services)")
    }


    func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
    {
        print("*******************************************************")
        if let charcterstics = service.characteristics
        {
            print("characteristics :")
            for char in charcterstics
            {
               /* if char.uuid == buttonCharacteristicUUID
                {
                    buttonCharacteristic = char
                    enableButtonNotifications(buttonCharacteristic!)
                    readButtonValue()
                }*/
                print(char.uuid.uuidString)
            }
        }
         peripheral.openL2CAPChannel(0x0025)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

0x25 PSM用于。您需要的是0x1F的ATT PSM,我也遇到过类似的问题。我通过创建一个变量在函数中保存“
channel:CBL2CAPChannel?
”来解决这个问题

func peripheral(_ peripheral: CBPeripheral, didOpen channel: CBL2CAPChannel?, error: Error?)

我只保存了“
频道。outputStream
”,这是我唯一需要的。但看起来如果你不保存它,它就会关闭

我尝试使用建议的PSM值,但问题仍然存在。以下是错误:[CoreBluetooth]警告:未知错误:582[CoreBluetooth]无法打开L2CAP通道OK,为什么需要连接L2CAP?您的设备通过L2CAP提供哪些服务?