How to tell if a user rejects bluetooth pairing?

So I am developing an application which interacts with a bluetooth peripheral, and I am running into the issue that there is currently no way to tell if the user rejected the peripheral's pairing request or not.



The current flow which is implemented is:



1. Scan for peripherals

2. Connect to peripheral

3. Discover services

4. Discover characteristics

(Pairing request is sent here by the peripheral, and the OS presents the pairing permission popup)

5. Read from characteristics



I would like to present an error state if the user rejects the pairing request, but I do not seem to be able to tell whether this has happened:



- There is no error callback executed on the CBCentralManagerDelegate or CBPeripheralDeleagate

- All the characteristics are discovered, whether or not paring has been accepted

- Reading from/ writing to characteristics fails silently: i.e. the peripheral just doesn't return a value when a characteristic is read from, but there's no affirmative error to let me know that it's because of a permission failure.



According to [this article](https://medium.com/@kbabcockuf/bridging-the-gap-bluetooth-le-security-653078852c24) it indicates that there's no direct way to know that the pairing request was cancelled.



According to [this answer](https://stackoverflow.com/questions/28351579/bluetooth-4-0-low-energy-and-ios-how-do-i-detect-if-device-is-bondable-or-not) it looks as if there is not currently a direct way to detect whether a peripheral is bonded in iOS.



Is there any known workaround for this issue?

Replies

In IOBluetoothDevicePairDelegate, there is a func:


optional func devicePairingFinished(_ sender: Any!, error: IOReturn)


What is the error code you receive when user deny pairing ?

Doesn't the return code let you know that user refused pairing ?

Sorry maybe I should have been more specific: this is for an iOS application. It looks like IOBluetooth is only available on macOS: is there something analagous in CoreBluetooth?