Skip to content

fix(darwin): add DidFailToConnectPeripheral handler#430

Open
acouvreur wants to merge 1 commit intotinygo-org:devfrom
acouvreur:add-didFail
Open

fix(darwin): add DidFailToConnectPeripheral handler#430
acouvreur wants to merge 1 commit intotinygo-org:devfrom
acouvreur:add-didFail

Conversation

@acouvreur
Copy link
Copy Markdown
Contributor

@acouvreur acouvreur commented Mar 30, 2026

When using the Connect on peripherals with an unstable state, I've found that it might be because of the missing DidFailToConnectPeripheral handler (https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/centralmanager(_:didfailtoconnect:error:)?language=objc)

After successfully establishing a local connection to a peripheral, the central manager object calls the centralManager:didConnectPeripheral: method of its delegate object. If the connection attempt fails, the central manager object calls the centralManager:didFailToConnectPeripheral:error: method of its delegate object instead. Attempts to connect to a peripheral don’t time out. To explicitly cancel a pending connection to a peripheral, call the cancelPeripheralConnection: method. Deallocating peripheral also implicitly calls cancelPeripheralConnection:.

So this should properly handle the connection failed event.

Note:

I would like to be able to use that error object. However, it requires to completely change the channel type.

I might do another PR later.

@deadprogram
Copy link
Copy Markdown
Member

Is there any way to test this out @acouvreur?

@acouvreur
Copy link
Copy Markdown
Contributor Author

Is there any way to test this out @acouvreur?

Rare cases when you connect to a device and it fails for some reason, like you were too far from the device but close enough to get signal.

Based on CoreBluetooth documentation, it is clear to me that we need this handler in case of error, because right now only the happy path is implemented.

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.

2 participants