question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

new BleManager() failed on componentWillMount

See original GitHub issue

In my own component below, I try to play with the ble but get some error:

undefined is not an object (evaluating 'BleModule.createClient')

Looks like in BleManager.js, it can not import BleModule. Any idea?

import { BleManager } from 'react-native-ble-plx';

export default class Discover extends Component {

	constructor(props) {
	  super(props);
	
	  this.state = {
	  	device: { id: '', name: '' },
	  	scanning: false
	  };
	}
	componentWillMount() {
	    this.manager = new BleManager();
	    this.subscriptions = {}
	    this.manager.onStateChange((newState) => {
	      console.log("State changed: " + newState)
	    });
	}
	componentDidUpdate(prevProps, prevState) {
		if (this.state.scanning) {
			this.manager.startDeviceScan(null, null, (error, device) => {
				if (!error) {
					console.log("Found device: ", device);
					this.setState({
						device,
						scanning: false
					})
				}
			});
		}
	  
	}
	componentWillUnmount() {
	    this.manager.destroy();
	    delete this.manager;
  	}
	render() {
		const { device } = this.state;
		return (
			<View style={{ flex: 1, justifyContent: 'center' }}>
				<Text>
				  {device.id} -- {device.name}
				</Text>
				<ButtonView
					onClick={this._startScan.bind(this)}
					text={'Start scanning'}
					color={'#beffc6'}/>
          
			</View>
		);
	}
	_startScan() {
		this.setState({ scanning: true });
	}
};

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
brancooo1commented, Feb 7, 2018

Guys, to solve it, just go through the whole manual installation of ble-plx https://github.com/Polidea/react-native-ble-plx#manually Make sure, from point 1, that everything is as it should be by documentation.

It’ll work 😉

0reactions
Benjamin-Lin-Xcommented, Nov 11, 2017

@haohcraft I am having the same issue while using expo too. Please tell me how to fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

new BleManager() failed on componentWillMount #56 - GitHub
In my own component below, I try to play with the ble but get some error: undefined is not an object (evaluating 'BleModule....
Read more >
react-native-ble-plx 2.0.2 | Documentation
Device instance which can be retrieved only by calling bleManager.startDeviceScan(). new Device(nativeDevice: NativeDevice, manager: BleManager). Parameters.
Read more >
Unable to use react native Bluetoothel - Stack Overflow
I never ask for user permission and it gives error Deivce is not authorized ... new BleManager(); this.state = { }; } componentWillMount() ......
Read more >
react-native-ble-plx.BleManager JavaScript and Node.js code ...
First step is to create BleManager which should be used as an entry point // to all BLE related functionalities const manager =...
Read more >
react-native-ble-manager - npm
The promise is resolved when either new bond successfully created or bond already existed , otherwise it will be rejected. Examples. BleManager.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found