ios - CBPeripheral didUpdateValueForCharacteristic, maid synchrone -


i have ble peripheral build on known (by me) serial peripheral. serial peripheral have whole home maid lib, implement serial protocol. protocol follow rule : send message receive answer.

right. have re-implemented communication on bluetooth, using corebluetooth.framework , work not bad. main problem wait until didupdatevalueforcharacteristic called before considering reply. (thank stackoverflow guys, have found number of reply here have save life)

but when talking device must :

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     dispatch_async(m_processingqueue, ^{         bool ok = [myperipheral excecutecommand];     });  } 

if :

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      bool ok = [myperipheral excecutecommand]; } 

the didupdatevalueforcharacteristic not called. execute command times out, , return false. didupdatevalueforcharacteristic called after all, data in it.

i have discorvered didupdatevalueforcharacteristic called in main thread :

- (void)peripheral:(cbperipheral *)peripheral didupdatevalueforcharacteristic:(cbcharacteristic *)characteristic error:(nserror *)error {     nslog(@"didupdatevalueforcharacteristic %@", [nsthread ismainthread]?@"is main thread":@"is not main thread"); // wich reply true ! } 

so if not calling [myperipheral excecutecommand]; in thread, main thread blocked, , never let didupdatevalueforcharacteristic called.

finally question : there way make didupdatevalueforcharacteristic called in background thread ?

thank !


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -