Swift: Select Queue for Bluetooth Central Manager

I am working on an application that will connect to a smart device via BLE and communicate with it.

Question: In which queue is it best to deal with bluetooth events?

I read a lot of tutorials and in all of them I found this:

centralManager = CBCentralManager(delegate: self, queue: nil)

They prefer to handle bluetooth events in the main queue ( queue: nil), but I believe this is not a good practice. Because it can be many requests sent to the peripheral device from the center, and many responses are sent from the peripheral to the central one.

I assume that this may be the reason that the application is slow and can negatively affect performance, am I right?

Will this flood the UI update queue?

+5
source share
3 answers

I have been using dispatch_get_global_queue (QOS_CLASS_BACKGROUND, 0) for the CBCentralManager for some time in my bluetooth projects and it has been working flawlessly.

^ Scratch it. I would not recommend using a global queue. The reason is that the global queue is parallel, and you probably need a sequential queue. Create a new one DispatchQueue(label: "CentralManager")and transfer it CBCentralManager.

. , , . .

+3

CBCentralManager CBPeripheral, .

dispatch_async - .

+1

Bluetooth, , - ; , .

-2

Source: https://habr.com/ru/post/1647987/


All Articles