2

I was reading "Performing Common Central Role Tasks" and it has info on how to discover peripheral and how to connect to peripheral, but I cant seem to find how to check if user selected Cancel or Pair on the popup because the popup comes when I call [myCentralManager connectPeripheral:peripheral options:nil];. I want not to connect to (or to disconnect from) peripheral if user clicks Cancel on the Pair popup. Can I call the Pairing popup some other way?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Spire
  • 1,055
  • 2
  • 17
  • 47
  • You shouldn't get a pairing popup until you attempt to read/write a characteristic with encryption required - unless perhaps your peripheral is initiating a pairing on connection. – Paulw11 Jan 17 '15 at 01:23

1 Answers1

7

The pairing process is initiated by attempting to read/write/notify on a characteristic that requires encryption.

If the pairing process completes then the appropriate CBPeripheralDelegate method (e.g. didUpdateValueForCharacteristic:) will be called with a nil error.

If the pairing process fails or is cancelled then the CBPeripheralDelegate method will be called with an NSError object that indicates that 'Encryption is insufficient' - CBATTErrorInsufficientEncryption.

If you get the insufficient encryption error you can either disconnect from the peripheral or retry the operation, which will display the pairing dialog again. I would suggest you retry a few times, say 3, in case the user made an error entering the PIN.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • I have used your suggestion and did this in `didUpdateValueForCharacteristic`: ` if(error.domain == CBATTErrorDomain && error.code == 5){[managerCentral cancelPeripheralConnection:peripheral];}` I guess this is the right way to go? – Spire Jan 23 '15 at 10:46