Handling incorrect PIN entry on BLE connection

I'm developing an app that pairs to a custom piece of hardware over BLE. Right now I'm working on a way to handle the case where the user mis-enters the PIN code. I see that didUpdateNotificationStateFor is passed an error message in this case saying "Encryption is insufficient.". But it seems like there has to be a better way to handle and react to that case.

Do I really need to rely on a string-compare against error message in order to determine when to display the instructions on how to reset everything and restart the pairing workflow? Is there something I'm missing in this documentation?

Answered by Engineer in 800414022

There is no need to do a string compare. The didUpdateNotificationStateFor function is passed an Error object of type CBATTError, and you can check the enumeration values of the .Code property.

For this case the value will be CBATTError.Code.insufficientEncryption

The various enumerations are described at https://developer.apple.com/documentation/corebluetooth/cbatterror-swift.struct/code


Argun Tekant /  DTS Engineer / Core Technologies

Accepted Answer

There is no need to do a string compare. The didUpdateNotificationStateFor function is passed an Error object of type CBATTError, and you can check the enumeration values of the .Code property.

For this case the value will be CBATTError.Code.insufficientEncryption

The various enumerations are described at https://developer.apple.com/documentation/corebluetooth/cbatterror-swift.struct/code


Argun Tekant /  DTS Engineer / Core Technologies

Handling incorrect PIN entry on BLE connection
 
 
Q