0

I'm using CoreBluetooth to communicate with nrf52 ble , i want to secure my app for a possible crash or bug like when you want to read from a Characteristic and this Characteristic not returning nothing , in this example noramly CoreBluetooth have a timer so after a while the communication with ble is disconnected , my question is : it's possible to cancel the request of read before the disconnection from Bluetooth. or is there an error of callback which allows me to control the situation before the disconnection of the app from bluetooth

my code :

    BT.readValue(for: mainCharacteristic)

the result should appear here if the Characteristic return a value

func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

    guard let data = characteristic.value else { return }
}
  • 1
    There is an error in the callback. It's the `error` parameter. What do you mean "before the disconnection from Bluetooth?" Do you mean before calling `cancelPeripheralConnection` or something else? – Rob Napier Feb 16 '21 at 18:14
  • No, in the case when you to read a characteristic and there is no answering(BLE card returning nothing ) the core bletooth continue to wait for a moment and after a while you lost the connection, so cancelPeripheralConnection is called automatically, – Nizar ELHRAIECH Feb 16 '21 at 20:30
  • if you want to understand better install the app nrfconnect and try to read from a characteristic (returning nothing) and after a while (it should be a timer) the app nrfconnect lost the connection with your ble card(nrf52) – Nizar ELHRAIECH Feb 16 '21 at 21:05

0 Answers0