iOSiOS BLE

蓝牙开发遇到的问题

2016-09-22  本文已影响1335人  飛呈Geek

问题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])
        }
    }

未完待续...
上一篇下一篇

猜你喜欢

热点阅读