Jake
Jake

Reputation: 329

How do I read a peripheral's characteristic without pairing with the other device in Swift?

My app functions as both a central and a peripheral. I have the one device searching for another broadcasting my service UUID. This works fine until I connect to the peripheral. Then a "Bluetooth Pairing Request" appears on both devices asking to confirm the 6-digit code and pair with the other device. I do not want this notification to appear and I do not want devices to start appearing in the Settings -> Bluetooth.

In CBCentralManager.connectPeripheral(CBPeripheral, options: nil) I thought there might be an option that can be specified in the options dictionary to prevent the alert but there are only three and none of them do what I want.

Is it possible to read a peripheral's RSSI and characteristics without connecting? Or is it possible to connect to the peripheral without displaying a pair notification to the user?

Thanks.

UPDATE:

I have used a TSI to get this resolved. He directed me to an Apple sample project called BTLE Transfer. He says that the pairing should not happen and that it doesn't happen in the sample project. I built the project and ran it and it does present the same exact pair request that my app does. I don't know if anyone else cares or is also struggling with this but I will update my question with new information and I will answer it if I find a solution.

UPDATE #2:

I believe this is a bug in iOS 8.4. I have submitted a bug report to Apple outlining the details of the bug.

Upvotes: 5

Views: 2558

Answers (1)

MAZ
MAZ

Reputation: 934

I was working on BLE module for my app and I encountered same problem, however after lots of R&D I found the solution. (Though Jake asked this question more than 3 years ago and he might have found the solution but I am posting my answer so that anyone else with same problem could get benefit.)

Is it possible to read a peripheral's RSSI and characteristics without connecting?

YES

Or is it possible to connect to the peripheral without displaying a pair notification to the user?

YES and NO (it depends)

As it is you who is creating the peripheral so you decide if "Bluetooth Pairing Request" is required or not. Basically you set properties and permissions on the characteristics (which are being advertised). You can see all available properties here and permissions here. So by setting CBCharacteristicPropertyRead property and CBAttributePermissionsReadable permission on the characteristic I was able to read characteristic data without pairing. You can see how to configure characteristics according to specific properties and permissions here.

Upvotes: 1

Related Questions