2
votes

BLE(Bluetooth Low Energy) Device Should get connected Without Scanning to my iPhone(App).

I have the BLE Address which I'm getting through Scanning the QRCode.

So from there I want the specific device(The one which I passed the address) connected without calling the (manager.scanForPeripherals(withServices: nil) ) As it will bring up all the devices .

For now I'm able to scan the QRCode of my BLE Device and Scan For All The Available devices then when I found my particular device. I'm Stopping the scan and connecting to it by using advertisement Data in

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber)

Is there a way to connect directly without scanning as I already have the address of the BLE device

Thanks in Advance .Any References would be helpful.

3
Please mention if u have any doubts in the questionnovice
Asking for off-site resources is considered off topic. please explain in your question what research you have done, what you have tried already and what problems you are having. then you wont get downvotes. I dont think you can connect to any BLE device without scanning for it to confirm it exists but someone else may know more about itScriptable
What is the problem with scanning? It only takes a few seconds or so and you can simply connect and stop scanning once you have found the device you are after. Once you have discovered the device the first time you can save its identifier and call retrievePeripherals to try and avoid the scan in future.Paulw11
Is Scanning Mandatory as I already have the device Address.(By scanning the QRCode).In android its possible it seem's(But I don't know for sure correct me if I'm wrong).novice

3 Answers

4
votes

You cannot connect to peripherals without performing a scan. While scanning the peripheral manager creates a unique id for each peripherals which is then used for connection. This unique id will be different for a same peripheral on different iPhones. So your idea will not work, you will have to perform a scan for connection.

1
votes

If you wish to reconnect to a previously discovered device you can store the device UUID and than use:

let retrievedPeripheral = centralManager.retrievePeripherals(withIdentifiers: [deviceUUID])

which will retrieve the CBPeripheral objects which match the provided UUID. You can than perform the connection using:

centralManager.connect(retrievedPeripheral[0], options: nil)

This does mean that the device has to be in range and advertising and there really isn't a way to check for that unless you scan. Hope this helps.

0
votes

I don't know for Iphone but on windows it is. just connect with the known address. It has some drawbacks: The device can be out of reach or already connected so you have to catch these situations.