美文网首页iOSiOS BLE
蓝牙开发遇到的问题

蓝牙开发遇到的问题

作者: 飛呈Geek | 来源:发表于2016-09-22 11:01 被阅读1335次

问题1:API MISUSE: <private> can only accept this command while in the powered on state

解决办法:

//CBCentralManagerDelegate
centralManagerDidUpdateState(_ central: CBCentralManager)

该方法执行后central.state == .poweredOn再去scan

问题2:[CoreBluetooth] API MISUSE: Cancelling connection for unused peripheral

解决办法:用成员变量保存引用

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        if peripheral.name == BLE_SERVICE_NAME {
            print(peripheral.name)
            self.peripheral = peripheral
            centralManager.connect(self.peripheral!, options: [CBConnectPeripheralOptionNotifyOnDisconnectionKey : true])
        }
    }

未完待续...

相关文章

网友评论

  • 3fbfd3c15df9::+1: :+1: 很好的解决了我的问题:smile:
  • MN的奇遇:大神 在吗 你这第一个是啥意思啊 可以用oc些一些思路吗

本文标题:蓝牙开发遇到的问题

本文链接:https://www.haomeiwen.com/subject/rtrzettx.html