问题
I want to make demo application, which contains following features.
- search and show device list in my device Bluetooth range.
- connect(pair) selected devices.
- then share string data.
For doing that I am using core Bluetooth framework(Central and peripheral classes). using that I am able to search devices, connect devices and transfer string data also.
but I am not able to authenticate devices before pairing(when I call connect method it is directly shown me connected status). how is it handled in ios?
also please suggest me I am on the right path or I need to use another library to implement this functionality.
回答1:
For anyone else beating their head against a wall, I have the solution to this issue. It's as simple as setting the AUTHENTICATION required flag for a characteristic on your BLE device. Once that flag is set, you need to attempt a READ from that service / characteristic using the iOS device. Once the read is requested, the BLE device will send back a failure message which then prompts iOS to display the PAIRING / BONDING popup. After that, you're golden.
Here is an example of a Cypress BLE device permission group. The settings are similar for most BLE embedded devices out there.
回答2:
yes it is possible to ask pairing request from BLE device to ios.
I followed below steps to make ios app to ask for pairing.
- edited my ble app to return error code 'RBLE_ATT_ERR_INSUFF_AUTHEN' using gatt write response function.
- attempted a write from ios app then i got a prompt to enter pairing key.
- used the randomly generated pairing key by BLE device to pair.
Paulw11's comment also helped me to solve that problem,
Regards Bharath GK
来源:https://stackoverflow.com/questions/43567569/how-to-ask-for-authentication-before-connect-to-devices-using-bluetooth