Gusev Slava Gusev Slava - 1 year ago 162
iOS Question

Swift: Choose queue for Bluetooth Central manager

I'm working on the app that will connect with a smart device via BLE and communicate with it.

The question is: In what queue is the best practice to handle bluetooth events?

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

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

They choose to handle bluetooth events in main queue (
queue: nil
), but I suppose that it's not good practice. Because it could be a lot of queries send to peripheral device from central and a lot of answers send from peripheral to central.

I assume this might be the reason of the app working slowly and might detrimentally affect the productivity, am I right?

Will this flood the UI update queue?

Answer Source

I am using dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0) for the CBCentralManager for some time in my Bluetooth projects and it is working flawlessly.

All the delegate methods will be delivered to the queue you specify. If you do some very light operations on these methods, I guess you could keep the main queue. But it is better to use a background queue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download