File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ use std::{
3838 fmt:: { self , Debug , Formatter } ,
3939 ops:: Deref ,
4040 thread,
41+ time:: Duration ,
4142} ;
4243use tokio:: runtime;
4344use uuid:: Uuid ;
@@ -887,6 +888,19 @@ impl CoreBluetoothInternal {
887888 {
888889 trace ! ( "Writing value! With kind {:?}" , kind) ;
889890 unsafe {
891+ if kind == WriteType :: WithoutResponse {
892+ // probably better idea would be to wait for the result of peripheral.peripheralIsReadyToSendWriteWithoutResponse
893+ let mut attempts = 0 ;
894+ while !peripheral. peripheral . canSendWriteWithoutResponse ( )
895+ && attempts < 100
896+ {
897+ attempts += 1 ;
898+ // min. connection interval time is 15ms. see the document:
899+ // https://developer.apple.com/library/archive/qa/qa1931/_index.html
900+ thread:: sleep ( Duration :: from_millis ( 15 ) ) ;
901+ }
902+ }
903+
890904 peripheral. peripheral . writeValue_forCharacteristic_type (
891905 & NSData :: from_vec ( data) ,
892906 & characteristic. characteristic ,
You can’t perform that action at this time.
0 commit comments