Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are multiple instances of CBCentralManager objects supported?

Tags:

ios

Are multiple CBCentralManager instances supported? Can I create two CBCentralManager instances in two different viewcontrollers in my app, and both connect to the same peripheral.

As question(Multiple CBCentralManager instances?) mentioned, there are some Apple mailing lists stating that it's not supported, however I have also found "Note: Because apps can have multiple instances of CBCentralManager and CBPeripheralManager objects, be sure each restoration identifier is unique, so that the system can properly distinguish one central (or peripheral) manager object from another" in CoreBluetooth Programming Guide.

I don't know in which case should I create multiple instaces of CBCentralManager objects. Hope you can help me, thanks.

like image 611
SomnusLee Avatar asked Aug 26 '15 08:08

SomnusLee


2 Answers

Official answer:

Multiple CBCentralManager instances are supported. But you cannot have more than one instance connect to the same peripheral.

You can think of a CBCentralManager as a view controller. You can have one view controller manage multiple views, but you cannot have one view managed by multiple view controllers(or if you did, it wouldn't make sense)

like image 143
SomnusLee Avatar answered Oct 18 '22 19:10

SomnusLee


According to: https://forums.developer.apple.com/thread/20810 You can have multiple CBCentralManager instances in one app.

Can CBPeripheral instances be shared between CBCentralManager instances?

You can share the property data. If you are asking about the CBPeripheral object, you cannot. When a central manager connects to a peripheral, there will be a message link created, and any events from the peripheral will be routed to that particular central. Central managers can create their own instances of CPBeripheral for the same peripheral, and if both need to receive the same events (read above and decide whether this is necessary or a good idea), they will need to connect individually.

like image 1
Alfred Ly Avatar answered Oct 18 '22 19:10

Alfred Ly