Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bond/pair to a bluetooth LE device programmatically in swift Xcode?

I am currently trying to develop and application that allows users to bond to a Peripheral via a click of a button and the password will be automatically entered.

Is it possible to Bond and Remove Bond programmatically using swift?

like image 237
Mysterious_android Avatar asked Nov 09 '22 03:11

Mysterious_android


1 Answers

Pairing is initiated any time that you attempt to write to or read from a characteristic on the BLE device. However, if the device is not set to require authentication and/or bonding, you will not see the iOS popup which requests the PIN code.

I struggled with this with my HM-10 because I could write data to the characteristic using the Core Bluetooth (via Swift) function writeValue() without ever seeing the pairing popup.

I couldn't figure it out until I read the HM-10 (implements the IC cc2451) datasheet very closely and found that I needed to set the AT+TYPE to value 3. It defaults to 0 which means that the HM-10 does not require pairing/bonding so you never see the iOS popup.

You can read more about the details where I asked the question and ultimately found the solution and wrote it up: How do I pair and/or bond to BLE on iOS using Swift code and an HM-10 so data sent is encrypted?

like image 175
raddevus Avatar answered Nov 14 '22 22:11

raddevus