Post

Replies

Boosts

Views

Activity

How do I run CoreBluetooth in background thread?
So I managed to get CoreBluetooth functionality working in an objective c++ commandline application, however corebluetooth blocks the main thread:main.cppint main() { call_obj_c_corebluetooth_initialization(); // corebluetooth occupies main thread std::thread worker(do_cpp_stuff); // c++ code runs in background thread, but I want to run c++ in main loop }How can I set up corebluetooth properly when I initialize the CBCentralManager on a background thread?std::thread worker(call_objective_c_code_to_initialize_cbcentralmanager)things I know:Must call [[NSRunLoop currentRunLoop] run] after CBCentralManager initialization because CoreBluetooth needs a runloop for delegate callbacks.CoreBluetooth has a background mode (but I don't think background mode is activated with the background thread)things I tried:creating a serial dispatch queue and initializing CBCentralManager with it._centralQueue = dispatch_queue_create("centralqueue", DISPATCH_QUEUE_SERIAL); self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:_centralQueue options:nil]; [[NSRunLoop currentRunLoop] run];
2
0
2k
May ’20