Multiple CBPeripheral's for same device

社会主义新天地 提交于 2019-12-10 18:15:00

问题


When using the CoreBluetooth framework to access Bluetooth Low Energy devices, the CBCentralManager returns a CBPeripheral for the peripheral.

Multiple services are available on the peripheral and I would like to split the code that handles characteristic value updates for the different services into multiple classes. Therefore, I would need to attach multiple id<CBPeripheralDelegate> delegates to the peripheral. However, this is not possible because only one delegate is supported.

  • Is there a way to get multiple CBPeripheral instances for the same peripheral?

    If it is possible that multiple applications access the same peripheral, do they receive different CBPeripheral instances? If yes, do they see updates from the other application? (Say, application A writes a value to a characteristic, does application B's delegate also receive the [– peripheral:didWriteValueForCharacteristic:error:] message?)

  • Are there any elegant approaches to support splitting the event handling code into multiple classes?


回答1:


The answer for CoreBluetooth: How to design code for many characteristics (30 - 40)? has some design tips that may be helpful here. In short, create a mediating class that can be a CBPeripheralDelegate and supports multiple characteristic classes registering for whatever characteristic they desire.



来源:https://stackoverflow.com/questions/10836703/multiple-cbperipherals-for-same-device

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