yonran
yonran

Reputation: 19134

Can CoreBluetooth act as both a central and peripheral at the same time (Unknown error 0)?

I have an OSX app that does the following:

  1. Start the central manager [[CBCentralManager alloc] initWithDelegate:queue:] and wait for it to initialize.
  2. Connect to a Bluetooth LE peripheral using [CBCentralManager connectPeripheral:options:]
  3. Start the peripheral manager [[CBPeripheralManager alloc] initWithDelegate:queue:options:] and wait for it to initialize.
  4. Add services to the peripheral manager [CBPeripheralManager addService:] and wait for them to finish being added.
  5. Start advertising [CBPeripheralManager startAdvertising:] and wait for the result.

Now, my callback [CBPeripheralManagerDelegate peripheralManagerDidStartAdvertising:error:] gets an error: “Error Domain=CBErrorDomain Code=0 "Unknown error." UserInfo=0x7fb23bf7ba50 {NSLocalizedDescription=Unknown error.}”.

However, if I call [CBCentralManager cancelPeripheralConnection:] immediately before startAdvertising:, then the error goes away.

Is it impossible for a Mac to act in both Central Role and Peripheral Role at the same time? Does this limitation also exist on iOS? Is this a hardware-specific limitation, or is this inherent in Bluetooth LE?

I am testing this on a Mid 2011 Mac Mini running OSX 10.9 Mavericks.

Upvotes: 2

Views: 1391

Answers (1)

Penghe Geng
Penghe Geng

Reputation: 14601

I can confirm CoreBluetooth on iOS doesn't have this issue, at least not when I last tested it on iOS 6 on an iPhone 5. The iPhone can advertise as a BLE peripheral while talking to another BLE peripheral as the BLE Central at the same time. I don't have results on OS X. But I will be really suprised if OS X, on a much more powerful platform, has such limit.

Upvotes: 1

Related Questions