Here is the code that I use to create the CBCentralManager
eventQueue = dispatch_queue_create("com.ekko-tech.mycentral", DISPATCH_QUEUE_SERIAL);
dispatch_set_target_queue(eventQueue, dispatch_get_main_queue());
[self setCentralManager:[[CBCentralManager alloc] initWithDelegate:self queue:eventQueue options:bleInitOptions]];
I picked up this code from the OpenBLE project up in github.
Can anyone give me some advice on whether this is an appropriate approach? As I see it, the second line (dispatch_set_target_queue...) has the effect of enqueuing BLE work on the main queue which is processed by the main thread. This being the case, there is no point to this code. I could have equally done the exact same thing with a single line of code:
[self setCentralManager:[[CBCentralManager alloc] initWithDelegate:self queue:nil options:bleInitOptions]];
If the intention of the above code was to process BLE events in the background (or, more specifically, not in main queue co-mingled with UI events), I don't think it achieves that goal. The target queue specified above should not be the main queue but some other queue.
However, there are no serial queues available in GCD other than the main queue so is it alright to use a concurrent queue as the target queue? Here is how Ste Prescott (SCPCoreBluetoothManager - also in github) does it:
dispatch_queue_t backgroundQueue = dispatch_queue_create("me.ste.SCPCoreBluetoothCentralManager.queue", NULL);
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:backgroundQueue];
Here, backgroundQueue is a serial queue with a target queue of the default priority concurrent queue. The Ste Prescott code obviously works so I am assuming that this is the better way to do it.
Any comments would be welcome.
Kind regards,
Andrew Coad