• <legend id='EvPmB'><style id='EvPmB'><dir id='EvPmB'><q id='EvPmB'></q></dir></style></legend>

      <bdo id='EvPmB'></bdo><ul id='EvPmB'></ul>
    <i id='EvPmB'><tr id='EvPmB'><dt id='EvPmB'><q id='EvPmB'><span id='EvPmB'><b id='EvPmB'><form id='EvPmB'><ins id='EvPmB'></ins><ul id='EvPmB'></ul><sub id='EvPmB'></sub></form><legend id='EvPmB'></legend><bdo id='EvPmB'><pre id='EvPmB'><center id='EvPmB'></center></pre></bdo></b><th id='EvPmB'></th></span></q></dt></tr></i><div id='EvPmB'><tfoot id='EvPmB'></tfoot><dl id='EvPmB'><fieldset id='EvPmB'></fieldset></dl></div>

    1. <tfoot id='EvPmB'></tfoot>

    2. <small id='EvPmB'></small><noframes id='EvPmB'>

      1. Swift:为蓝牙中央管理器选择队列

        时间:2024-04-14
          <i id='RMHX9'><tr id='RMHX9'><dt id='RMHX9'><q id='RMHX9'><span id='RMHX9'><b id='RMHX9'><form id='RMHX9'><ins id='RMHX9'></ins><ul id='RMHX9'></ul><sub id='RMHX9'></sub></form><legend id='RMHX9'></legend><bdo id='RMHX9'><pre id='RMHX9'><center id='RMHX9'></center></pre></bdo></b><th id='RMHX9'></th></span></q></dt></tr></i><div id='RMHX9'><tfoot id='RMHX9'></tfoot><dl id='RMHX9'><fieldset id='RMHX9'></fieldset></dl></div>
          <tfoot id='RMHX9'></tfoot>

            <small id='RMHX9'></small><noframes id='RMHX9'>

            <legend id='RMHX9'><style id='RMHX9'><dir id='RMHX9'><q id='RMHX9'></q></dir></style></legend>

              <tbody id='RMHX9'></tbody>

                <bdo id='RMHX9'></bdo><ul id='RMHX9'></ul>

                1. 本文介绍了Swift:为蓝牙中央管理器选择队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发将通过 BLE 与智能设备连接并与之通信的应用程序.

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

                  问题是:处理蓝牙事件的最佳做法是在哪个队列中?

                  我已经阅读了很多教程,在所有教程中我都发现了这一点:

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

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

                  他们选择在主队列(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?

                  这会淹没 UI 更新队列吗?

                  Will this flood the UI update queue?

                  推荐答案

                  我在我的蓝牙项目中使用了 CBCentralManager 的 dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0) 一段时间,它工作完美.

                  ^ 从头开始.我不建议使用全局队列.原因是全局队列是一个并发队列,而您可能想要一个串行队列.创建一个新的 DispatchQueue(label: "CentralManager") 并将其传递给 CBCentralManager.

                  ^ 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.

                  这篇关于Swift:为蓝牙中央管理器选择队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:区别需要MainQueueSetup 和dispatch_get_main_queue? 下一篇:从队列更新活动的最佳方式

                  相关文章

                2. <small id='opmr2'></small><noframes id='opmr2'>

                  1. <i id='opmr2'><tr id='opmr2'><dt id='opmr2'><q id='opmr2'><span id='opmr2'><b id='opmr2'><form id='opmr2'><ins id='opmr2'></ins><ul id='opmr2'></ul><sub id='opmr2'></sub></form><legend id='opmr2'></legend><bdo id='opmr2'><pre id='opmr2'><center id='opmr2'></center></pre></bdo></b><th id='opmr2'></th></span></q></dt></tr></i><div id='opmr2'><tfoot id='opmr2'></tfoot><dl id='opmr2'><fieldset id='opmr2'></fieldset></dl></div>

                    • <bdo id='opmr2'></bdo><ul id='opmr2'></ul>

                    1. <legend id='opmr2'><style id='opmr2'><dir id='opmr2'><q id='opmr2'></q></dir></style></legend>
                    2. <tfoot id='opmr2'></tfoot>