Skip to content

Commit f35cadd

Browse files
committed
fix: corebluetooth canSendWriteWithoutResponse
1 parent 295f817 commit f35cadd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/corebluetooth/internal.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use std::{
3838
fmt::{self, Debug, Formatter},
3939
ops::Deref,
4040
thread,
41+
time::Duration,
4142
};
4243
use tokio::runtime;
4344
use 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,

0 commit comments

Comments
 (0)