简体   繁体   中英

Writing the value of a BLE device's characteristic at fast speed may break the CoreBluetooth framework of iOS

We use iPhone to interact with a BLE device through Core Bluetooth framework. Everything works fine, except the Core Bluetooth will crash when we power off the device while iOS is still writing characteristic by calling writeValue:forCharacteristic:type: . The write type is CBCharacteristicWriteWithoutResponse . In such circumstances we must reboot iPhone in order to connect to ANY BLE devices again, since turning off and on the bluetooth on iPhone is of no use.

I have made some tests on this problem and get some information that when we power off the BLE device, iOS needs some time to get the disconnection event, so writeValue:forCharacteristic:type: is still being called at this period, this may cause the CoreBluetooth framework crash! I don't know why the BLE stack of iOS can't handle this.

Any ideas on how to avoid such things when the device is out of power suddenly while iOS is still writing characteristic to it OR can writeValue:forCharacteristic:type: be called at some what safe manner?

Thanks!

I would recommend to use CBCharacteristicWriteWithResponse so that you can confirm that Peripheral receives data from central. If the Peripheral is turned off, then peripheral:didWriteValueFor will be invoked with error != nil. And you can write the logic not to send the data if any error occur.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM