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