novice
novice

Reputation: 451

BLE Device Should get connected Without Scanning

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.

Upvotes: 2

Views: 2480

Answers (3)

8azan
8azan

Reputation: 158

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.

Upvotes: 2

GrooverFromHolland
GrooverFromHolland

Reputation: 1029

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.

Upvotes: 0

Vaisakh Vinod
Vaisakh Vinod

Reputation: 277

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.

Upvotes: 4

Related Questions