Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I connect multiple BLE peripherals to an iOS device?

Currently my team is calling

[myCentralManager scanForPeripheralsWithServices:nil options:nil];

and then starting an NSTimer that fires in two seconds. During these two seconds, the Central Manager delegate method

centralManager:didDiscoverPeripheral:advertisementData:RSSI:

is used to create an array of CBPeripherals that we are interested in.

When the timer fires, we call connectPeripheral on every item in the array within a for loop.

I am worried that this is not the best way to connect to several devices at once. Should we wait for one device's connection process to complete before calling connectPeripheral on another device?

Thanks for any suggestions.

like image 768
Mgill404 Avatar asked Feb 15 '23 03:02

Mgill404


1 Answers

Have you experienced issues? If not, then do it the way you do.

Some additional thoughts:

  • Generally, it is advised to stop scanning before starting a connection request. The connection will be established significantly faster this way.
  • Starting multiple connections at once has no implications from the API side, however, it's possibly safer (from a robustness point of view) to do it sequentially. This way you can prevent overloading the Core Bluetooth stack.
  • Instead of an NSTimer, I'd rather use the GCD dispatch_after function but this is my personal preference. (Using ReactiveCocoa would be even better.)
like image 181
allprog Avatar answered Feb 17 '23 01:02

allprog