React-native-ble-plx: State gets Unsupported after refresh or JS crash

Created on 13 Nov 2019  路  6Comments  路  Source: Polidea/react-native-ble-plx

Prerequisites

  • [x] I am running the latest version
  • [x] I checked the documentation and found no answer
  • [x] I checked to make sure that this issue has not already been filed

Expected Behavior

After refreshing the app or having a JavaScript crash on iOS Bluetooth Adapter State should have the current state of BLE (same that it was if it wasn't changed by an external condition).

Current Behavior

Sometimes it comes as Unsupported even though it is PoweredOn, it just goes back to normal if the app is killed and opened again. Happens randomly.
Is there a way to refresh the connection with hardware components?

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Subscribe and log BLE state changes with onStateChange
  2. Connect with a BLE device
  3. Start monitoring data
  4. Toggle RN commands and press Refresh
  5. Notice that the state goes from Unknown to Unsupported and get stuck in this state

To have it happen it could be needed to run these steps more than once since it happens randomly.

Context

System:
    OS: macOS 10.15
    CPU: (4) x64 Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
    Memory: 21.60 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.13.0 - /var/folders/j0/mcc56qzn2934szgsqdwslc_40000gn/T/yarn--1573647094820-0.6661912929450491/node
    Yarn: 1.12.1 - /var/folders/j0/mcc56qzn2934szgsqdwslc_40000gn/T/yarn--1573647094820-0.6661912929450491/yarn
    npm: 6.5.0 - ~/.nvm/versions/node/v10.13.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
    Android SDK:
      API Levels: 23, 24, 25, 26, 27, 28
      Build Tools: 23.0.1, 23.0.3, 25.0.2, 26.0.2, 27.0.3, 28.0.2, 28.0.3
      System Images: android-27 | Google Play Intel x86 Atom
      Android NDK: 16.1.4479499
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.2 => 0.61.2
  • Library version: 1.1.0
  • Platform: iOS

Will keep adding more info as I troubleshoot this.

bug stale

All 6 comments

Same issue. It has something to do with scanning the devices to soon after manager creation. 馃し Haven't been able to figure it out yet, but for testing purposes I'm delaying BLE functions (scan) after BleManager creation by 1s.

You should always wait for "PoweredOn" state before doing anything with a Bluetooth. You can use this call to monitor it: https://polidea.github.io/react-native-ble-plx/#blemanageronstatechange

@Cierpliwy I got the same issue.
After refreshing the app to update the new changes, the stage of BleManager changed to Unsupport.
I have to close the app and reopen again.

Any idea?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Same problem here. It never transitions to PoweredOn in this case, only after hard restarting the app. Is there anything we can do?

We ran into this issue when initializing the BleManager in react state, causing react to re-initialize the BleManager on each render:
const [bleManager] = useState(new BleManager())

We fixed it by moving the initialization outside the component. You could also use the callback form of useState:
const [bleManager] = useState(() => new BleManager())

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kevinmeyvaert picture kevinmeyvaert  路  4Comments

paddlefish picture paddlefish  路  4Comments

lenninlc picture lenninlc  路  3Comments

SlavaInstinctools picture SlavaInstinctools  路  4Comments

biks152207 picture biks152207  路  3Comments