Corebluetooth Advertising Problem on Catalina

Hello,

I have some code to broadcast a BLE ad in Objective-C that worked well in Mojave, but has broken since moving to Catalina. The problem seems to stem from providing a value for the dispatch queue to the CBPeripheralManager instance versus NULL:

Calling _peripheralManager startAdvertising within CBPeripheralManagerDelegate peripheralManagerDidUpdateState works:
Code Block
_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:NULL];

Calling _peripheralManager startAdvertising within CBPeripheralManagerDelegate peripheralManagerDidUpdateState does not work:
Code Block
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
_peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:q];

As I mentioned, both versions worked in Mojave, so something is different in Catalina that I'm not able to discern that causes the version where the dispatch queue is provided to not work.

Thanks,
Larry

You really shouldn’t be using a concurrent queue here. Even if Core Bluetooth does the right thing — and I’m not a Core Bluetooth expert, so I don’t have an opinion on that topic — it’s very easy to get hopelessly confused when using a concurrent queue because you can have multiple callbacks running concurrently.

Plus, using a concurrent queue is generally a bad idea from a Dispatch perspective. For more on this, see WWDC 2017 Session 706 Modernizing Grand Central Dispatch Usage.

At a minimum, you should switch to using a serial queue.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thanks for the reply! Switching to the concurrent queue was my attempted fix when I initially encountered this change in behavior. The problem persists even when I create the queue in this manner:
Code Block
dispatch_queue_t q = dispatch_queue_create("com.example.MyQueue", NULL);

Fair enough. Alas, this puts this question firmly in the Core Bluetooth side of things, and that’s not something I can help you with.

If no one else chimes in, I recommend that you open a DTS tech support incident and talk to DTS’s Core Bluetooth specialist.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Corebluetooth Advertising Problem on Catalina
 
 
Q