8
votes

I'm trying to create a BLE pairing user-experience screen in my app. The app scans for our BLE device, and when discovered, automatically connect it to the centralManager. The System then shows a Bluetooth Pairing Request dialog (not part of my app, but iOS's). The user has two options - Pair/Cancel. Thing is - Even when the Cancel action is being selected by the user - The peripheral still stays connected to the centralManager. (the centralManagerDidConnect function is being trigger) Even though it's not paired with the phone. Is there any way that I can know if the user chose to pair the device, or to cancel the pairing ??? Thanks!

2
If pairing is successful you will be able to read an encrypted characteristic successfullyPaulw11
Hi, I still manage to read characteristics even if I choose to cancel...,Shahar Biran
Then why are you pairing? Pairing (actually bonding) is only initiated when an encrypted characteristic is encountered. If you don't have any need for encryption then you have no need for pairing.Paulw11
I may have misunderstood what do you mean by "encrypted characteristic". I first call "ConnectToPeripheral" function, and then "Discover characteristics" (after of course discovering the services). I get a positive callback even when i hit the "cancel" button in the dialog. Is that what you meant ? Our BLE device uses HID - I think that's why there's a need for pairing.Shahar Biran
The HID portion and pairing is nothing to do with CoreBluetooth and your app. HID is managed by iOS alone. For a GATT profile (which is what is used with Core Bluetooth) pairing is only initiated when one of the characteristics is configured with encryption. This is why you can still read the characteristic regardless of the pairing state; pairing isn't required for your characteristic. You could require encryption on one of your characteristics and then if you can read that you know that pairing has taken place or you could expose the pairing state from your peripheral via a characteristicPaulw11

2 Answers

3
votes

Apple is pretty stupid to not have any API, callback or whatsoever about pairing. The only thing I know is that you let your BLE device send a notification you listen to in your app how the pairing goes. iOS will send a "Pairing Failed" SMP command when the user presses cancel for example.

3
votes

Find my detailed answer to a similar question here.

You should basically write to a characteristic of the device after pairing and check if the write was successful