CoreBluetooth - Can connectPeripheral be called multiple times

為{幸葍}努か 提交于 2020-01-04 02:05:46

问题


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

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?


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/17935287/corebluetooth-can-connectperipheral-be-called-multiple-times

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