Multiple CBCentralManagers in one app?

Is it OK to have multiple instances of CBCentralManager in a single app?


In my case, there will only be two instances and each one is managing a different kind of device. I do need to be able to scan for both devices at the same time.


I realize that this is not the best architecture, but I'm in a situation where I'm being asked to basically merge two apps into a single app, and each of those apps has its own very complex logic that I don't want to disturb.


Thanks,

Frank

Replies

Yes this is a common design pattern and it can be very beneficial over trying to use a single instance of the CBCentralManager.


You may also find it useful to subslass CBPeripheral multiple times as well.

You can even use multiple CBCentralManager instaces in order to communicate with the same peripheral

When I tried this, I found that whichever CBCentralManager I created second didn't work because the state was being reported as "Unsupported". Is there some trick to instantiating these objects to ensure they both work?

What OS and device do you use?
Multiple CBCentralManagers works for me on iOS, watchOS and macOS.