同一设备的多个CBPeripheral [英] Multiple CBPeripheral's for same device
问题描述
使用CoreBluetooth框架访问低功耗蓝牙设备时, CBCentralManager
返回 CBPeripheral
用于外围设备.
When using the CoreBluetooth framework to access Bluetooth Low Energy devices, the CBCentralManager
returns a CBPeripheral
for the peripheral.
外围设备上有多个服务,我想将处理不同服务的特征值更新的代码分成多个类.因此,我需要将多个id<CBPeripheralDelegate>
委托附加到外围设备.但是,这是不可能的,因为仅支持一个委托.
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.
-
是否可以为同一外设获取多个
CBPeripheral
实例?
如果可能有多个应用程序访问同一个外围设备,那么它们会收到不同的CBPeripheral
实例吗?如果是,他们是否看到其他应用程序的更新? (例如,应用程序A向特征写入值,应用程序B的委托是否还收到[–外周:didWriteValueForCharacteristic:错误:]消息?)
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?
推荐答案
答案 ://stackoverflow.com/questions/18897304/corebluetooth-how-to-design-code-for-many-characteristics-30-40> CoreBluetooth:如何为多种特性(30-40)设计代码?提供一些设计技巧,可能会对您有所帮助.简而言之,创建一个中介类,该中介类可以是CBPeripheralDelegate
,并支持针对每个特性注册的多个特性类.
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.
这篇关于同一设备的多个CBPeripheral的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!