简体   繁体   中英

iOS Core Bluetooth Pin Code

I have a BLE peripheral that requires a PIN code. I am connecting to this peripheral using Core Bluetooth CBCentralManager on iOS 7.

When I connect to this peripheral, 'didConnectPeripheral' (central delegate) gets called before the PIN code authentication is successfully completed.

iOS only displays the pin code dialog after 'didConnectPeripheral' is called.

I need to start interacting with the peripheral as soon as this PIN code dialog is finished and authentication process is complete. How can I determine when this has happened?

The challenge is to only proceed after the authentication is successful, but:

  1. iOS calls 'didFailToConnectPeripheral' prior to the dialog showing.
  2. iOS does not call 'didConnectPeripheral' again if the PIN code authorisation succeeded.
  3. iOS does not call 'didFailToConnectPeripheral' again if the PIN code authorisation failed.

From the above, I have been unable to determine:

  1. When the dialog completes.
  2. Whether the PIN code authorisation was successful.

Any help would be appreciated.

From my experience with CoreBluetooth you will not receive any information as to whether you are authorized and when the pin code authorization is completed until you attempt an action that is unauthorized, which will fail with one of three error responses:

InsufficientEncryption
InsufficientAuthentication
InsufficientAuthorization

The peripheral is what determines which error you will be returned. (Technically they are defined by the GATT in BLE 4.X specs but it is all implementation detail controlled on the peripheral side)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM