Skip to content

Commit b000925

Browse files
committed
chore: check is canSendWriteWithoutResponse is supported
1 parent f35cadd commit b000925

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ objc2-foundation = { version = "0.2.2", default-features = false, features = [
5959
"NSString",
6060
"NSUUID",
6161
"NSValue",
62+
"NSProcessInfo",
6263
] }
6364
objc2-core-bluetooth = { version = "0.2.2", default-features = false, features = [
6465
"std",

src/corebluetooth/internal.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use objc2_core_bluetooth::{
3131
CBCharacteristicProperties, CBCharacteristicWriteType, CBDescriptor, CBManager,
3232
CBManagerAuthorization, CBManagerState, CBPeripheral, CBPeripheralState, CBService, CBUUID,
3333
};
34-
use objc2_foundation::{NSArray, NSData, NSMutableDictionary, NSNumber};
34+
use objc2_foundation::{NSArray, NSData, NSMutableDictionary, NSNumber, NSProcessInfo};
3535
use std::{
3636
collections::{BTreeSet, HashMap, VecDeque},
3737
ffi::CString,
@@ -369,6 +369,7 @@ impl PeripheralInternal {
369369
struct CoreBluetoothInternal {
370370
manager: Retained<CBCentralManager>,
371371
delegate: Retained<CentralDelegate>,
372+
can_send_without_response_supported: bool,
372373
// Map of identifiers to object pointers
373374
peripherals: HashMap<Uuid, PeripheralInternal>,
374375
delegate_receiver: Fuse<Receiver<CentralDelegateEvent>>,
@@ -492,8 +493,16 @@ impl CoreBluetoothInternal {
492493
msg_send_id![CBCentralManager::alloc(), initWithDelegate: &*delegate, queue: queue]
493494
};
494495

496+
let process_info = unsafe { NSProcessInfo::processInfo() };
497+
let version = unsafe { process_info.operatingSystemVersion() };
498+
let mut can_send_without_response_supported = false;
499+
if (version.majorVersion, version.minorVersion) >= (11, 2) {
500+
can_send_without_response_supported = true;
501+
}
502+
495503
Self {
496504
manager,
505+
can_send_without_response_supported,
497506
peripherals: HashMap::new(),
498507
delegate_receiver: receiver.fuse(),
499508
event_sender,
@@ -888,7 +897,9 @@ impl CoreBluetoothInternal {
888897
{
889898
trace!("Writing value! With kind {:?}", kind);
890899
unsafe {
891-
if kind == WriteType::WithoutResponse {
900+
if kind == WriteType::WithoutResponse
901+
&& self.can_send_without_response_supported
902+
{
892903
// probably better idea would be to wait for the result of peripheral.peripheralIsReadyToSendWriteWithoutResponse
893904
let mut attempts = 0;
894905
while !peripheral.peripheral.canSendWriteWithoutResponse()

0 commit comments

Comments
 (0)