That bug was a tricky one. I was wondering why I couldn't properly detect iOS errors like Authentication is insufficient. or Encryption is insufficient. which happen after "forgetting" a BLE device and then trying to read a characteristic. Even when wrapping a try ... catch block around a read() call, read() only returned a null buffer instead of throwing an error.
It took me a while to find the underlying problem which is an NSError occurring in peripheral(_:didUpdateValueFor:error:) directly being passed as argument for RCTResponseSenderBlock although it is not a standard JSON type. As a result, on the Javascript-side of React Native the NSError was swallowed and came out as null, which was interpreted as no error at all with a null array.
I fixed all places where the error was directly passed and now read() correctly throws an error as expected in my code.
That bug was a tricky one. I was wondering why I couldn't properly detect iOS errors like
Authentication is insufficient.
orEncryption is insufficient.
which happen after "forgetting" a BLE device and then trying to read a characteristic. Even when wrapping atry ... catch
block around aread()
call,read()
only returned a null buffer instead of throwing an error.It took me a while to find the underlying problem which is an NSError occurring in peripheral(_:didUpdateValueFor:error:) directly being passed as argument for
RCTResponseSenderBlock
although it is not a standard JSON type. As a result, on the Javascript-side of React Native the NSError was swallowed and came out as null, which was interpreted as no error at all with a null array.I fixed all places where the error was directly passed and now
read()
correctly throws an error as expected in my code.I think this also fixes at least this issue I found during debugging: https://github.com/innoveit/react-native-ble-manager/issues/590