Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: connect() is not throwing error if trying to connect to a peripheral which is not reachable #1042

Open
lyxiangmelissali opened this issue Dec 30, 2024 · 1 comment

Comments

@lyxiangmelissali
Copy link

I am calling your library (version 1.7.8) function
ble.withPromises.connect(scannedDeviceId, mySuccessCallbackFunction, myErrorCallbackFunction);
also tried
ble.connect(scannedDeviceId, mySuccessCallbackFunction, myErrorCallbackFunction);
Both with the same behaviour (see case 4).
I am connecting to a ble device from our capacitor (version 6.0.0) app on an iPhone or android phone (iPhone 13 mini or Samsung Galaxy S10e).

Cases:

  1. iOS and Android phone: returning PeripheralDataExtended data in mySuccessCallbackFunction successfully if ble is enabled.
  2. iOS and Android phone: entering myErrorCallbackFunction if ble is disabled with errorMessage "Ble is disabled" from BLEError interface. This shows that myErrorCallbackFunction is working.
  3. Android: entering myErrorCallbackFunction if ble is enabled and peripheral is not reachable (e.g. distance from phone to ble device) - errorMessage "Peripheral disconnected" from BLEError interface
  4. iOS: not entering myErrorCallbackFunction if ble is enabled and peripheral is not reachable. There is no response from neither callback function. Also there is no "Peripheral disconnected" errorMesage like in Android. Is this intended behaviour, or some bug in the connect() function?

Thanks for your help.

@peitschie
Copy link
Collaborator

Hi @lyxiangmelissali

What you are describing here are differences between how Android and iOS treat connections.

iOS has no notion of a connection timeout, so the connect call continues until the peripheral is found and a connection is attempted. Meanwhile, Android has a connection timeout that reports roughly 20-30s after attempting to connect.

I don't have any plans to change this behaviour, as it's been this way in the plugin for too long. If you have the time though, I'd happily accept a pull request that added these notes to the documentation for connect to make this behaviour clearer to developers?

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

No branches or pull requests

2 participants