new BleManager() failed on componentWillMount
See original GitHub issueIn 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:
- Created 7 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 😉
@haohcraft I am having the same issue while using expo too. Please tell me how to fix it.