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?
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.