Swift: Choose queue for Bluetooth Central manager

一曲冷凌霜 提交于 2019-12-04 09:56:28

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.

^ Scratch that. I wouldn't recommend using the global queue. The reason is that the global queue is a concurrent one and you probably want a serial one. Create a new DispatchQueue(label: "CentralManager") and pass it to the CBCentralManager.

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.

You should definitely use a seperate queue for the CBCentralManager and preferrably also use it for all the communication with the CBPeripheral object - so your main queue is not getting blocked.

dispatch_async the events to your queue should not be a problem - as long as read/write requests are not getting delayed.

From Bluetooth perspective, I don't think queue the events is a best practice; except you want to delay the sending messages.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!