Skip to content

Conversation

szymonlesisz
Copy link
Contributor

Hi,

I've run into issue with WriteType::WithoutResponse on macos.
im trying to send ~2MB of data in shortest time possible however corebluetooth keeps loosing the packects shortly after the start.

When you use CBPeripheral.writeValue(_:for:type:) with .withoutResponse, CoreBluetooth:
- Queues the writes internally
- Starts transmitting them during connection intervals.
- Does not notify when it’s safe to send more.
- Silently drops writes if the queue is overwhelmed

while looking up for solutions in other bluetooth libs i came across this technical document and this guide

i belive the ultimate fix would be to use peripheral.peripheralIsReadyToSendWriteWithoutResponse as described in the guide but i dont see a easy way how to implement this method (missing CBPeripheralDelegate reference)

so i decided to use attempts loop and check every 15ms (Interval Min stated in the document) if it is safe to send another packet. the loop ends if true or after 100 retries (1500ms < connSupervisionTimeout stated in the document)

The only problem is that canSendWriteWithoutResponse was introduced in macos 11.0 (Big Sur) but it behaves unreliably until 11.2 - returning false until the first write is performed. That is why i've added can_send_without_response_supported flag which is set from the NSProcessInfo.

if you dont care about older OS releases (Big Sur was released in november 2020) i can drop the the second commit

@szymonlesisz szymonlesisz force-pushed the fix/corebluetooth-write-without-response branch from ea543f5 to e33736c Compare July 21, 2025 11:41
@szymonlesisz szymonlesisz force-pushed the fix/corebluetooth-write-without-response branch from e33736c to b000925 Compare July 21, 2025 11:42
@szymonlesisz
Copy link
Contributor Author

szymonlesisz commented Jul 28, 2025

i've noticed this pull request where is also OS version/support check added.

so im wondering maybe should i create CoreBluetoothInternal.support field? for example:

struct CoreBluetoothSupport {
    CanSendWithoutResponse: bool,
    ManagerAuthorization: bool,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant