React-native-ble-plx: Error after upgrading react-native to 0.49.3

Created on 11 Oct 2017  路  4Comments  路  Source: Polidea/react-native-ble-plx

Previously when it's on 0.48.0, everything was fine. Right after upgrading to 0.49.3, when I read state after registering for state change event, i.e.

bleManager.onStateChange((newState) => dispatch(bluetoothStateChanged(newState)));
const currentState = await bleManager.state();

I encounter the error

2017-10-11 19:15:49.104810+0800 IotApp[699:225767] [CoreBluetooth] API MISUSE: has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported
2017-10-11 19:15:49.111 [warn][tid:com.facebook.react.BleClientManagerQueue][RCTEventEmitter.m:54] Sending StateChangeEvent with no listeners registered.
2017-10-11 19:15:49.110848+0800 IotApp[699:225284] Sending StateChangeEvent with no listeners registered.

Has anyone encountered the same issue? Any advice on where I should begin looking other than downgrading?

Thanks.

Most helpful comment

I also ran across this issue. Fixed it by moving instantiation of the BleManager to componentDidMount.
Before:

  constructor() {
    super();
    this.ble = new BleManager();
  }
  componentWillMount() {
    this.ble.onStateChange(status => {
      this.setState({
        status,
      });
    }, false);
  }
  componentDidMount() {
    /* ... */
  }

After:

  componentDidMount() {
    this.ble = new BleManager();
    this.ble.onStateChange(status => {
      this.setState({
        status,
      });
    }, false);
  }

The docs do instantiate BleManager in the constructor.

Edit - I updated from 0.47.1 to 0.50.3.

All 4 comments

I also ran across this issue. Fixed it by moving instantiation of the BleManager to componentDidMount.
Before:

  constructor() {
    super();
    this.ble = new BleManager();
  }
  componentWillMount() {
    this.ble.onStateChange(status => {
      this.setState({
        status,
      });
    }, false);
  }
  componentDidMount() {
    /* ... */
  }

After:

  componentDidMount() {
    this.ble = new BleManager();
    this.ble.onStateChange(status => {
      this.setState({
        status,
      });
    }, false);
  }

The docs do instantiate BleManager in the constructor.

Edit - I updated from 0.47.1 to 0.50.3.

something wrong. i think it need to waiting the new BleManager() finish.

This is still an issue even after putting it in the componentDidMount lifecycle.

In addition, I am also getting warnings such as Sending 'DisconnectionEvent' with no listeners registered as well (after connecting, doing stuff, and disconnecting)

I fixed this error by going to ios/projectName/Info.plist and adding this:

    <key>NSBluetoothAlwaysUsageDescription</key>
    <string>Allow app to access your bluetooth</string>

I had previously added this directly in my app.json => expo.ios.infoPlist, but I guess that only works for managed expo projects, and I had to use a bare workflow to use this library.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

biks152207 picture biks152207  路  3Comments

SlavaInstinctools picture SlavaInstinctools  路  4Comments

devgeno picture devgeno  路  4Comments

haohcraft picture haohcraft  路  5Comments

BlackCod3 picture BlackCod3  路  3Comments