CoreBluetooth - 可以多次调用connectPeripheral [英] CoreBluetooth - Can connectPeripheral be called multiple times

查看:194
本文介绍了CoreBluetooth - 可以多次调用connectPeripheral的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某个应用程序是否可以尝试同时连接多个设备?

Can an application attempt to connect to multiple devices at once?

当应用程序调用'connectPeripheral'时,它将尝试连接一段时间以来未指定的时间没有超时。但是,如果第二次调用'connectPeripheral',它是否会取消之前的调用,或者应用是否会尝试同时建立两个独立的连接?

When an app calls 'connectPeripheral', it will attempt to connect for an unspecified amount of time since there is no time-out. However, if 'connectPeripheral' is called a second time, does it cancel out the previous call, or will the app attempt to make two separate connections at once?

推荐答案

在我的测试中,我看到你在连接前多次调用它,实际连接需要更长时间(实际上通常会阻止连接发生),但通常在正常运行后正常运行那。

In my testing I've seen if you call it multiple times prior to being connected, it will take longer to actually connect (and often actually prevents a connection from occurring), but usually functions as normal after that.

然而,我注意到的一件大事是你在<$内部尝试调用 connectPeripheral: c $ c> didConnectPeripheral:回调,你将自己置于一个无限循环中,一遍又一遍地继续返回 didConnectPeripheral:

However, the one massive thing I've noticed is if you try calling connectPeripheral: inside of the didConnectPeripheral: callback, you will put yourself in an infinite loop that keeps returning on didConnectPeripheral: over and over again.

长话短说,每一个 connectPeripheral:调用都应与 cancelPeripheralConnection匹配:(或 didDisconnectPeripheral:)调用,如果您不希望发生这样的未定义行为。

Long story short, every single connectPeripheral: call should be matched with a cancelPeripheralConnection: (or didDisconnectPeripheral:) call if you don't want undefined behavior like this to happen.

这篇关于CoreBluetooth - 可以多次调用connectPeripheral的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆