我是第一次接触React原生框架。我已经使用'create-react-native-app AwesomeProject‘创建了应用程序。我想在我的项目中使用BLE,所以我安装了'react-native-ble-plx‘模块,但是当我创建BleManager的实例时,它抛出了错误TypeError: Cannot read property 'createClient’of undefined。为什么抛出这个错误?我的App.js是:
import React from "react";
import { StyleSheet, Button, Text, View, Alert } from "react-native";
import { BleManager } from 'react-native-ble-plx';
export default class App extends React.Component {
constructor() {
super();
this.manager = new BleManager();
}
TestFunction() {
Alert.alert('Button Pressed !!!')
}
render() {
return (
<View style={styles.container}>
<Button onPress={ this.TestFunction } title="Learn
More"color="#841584" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
}
});发布于 2018-09-12 20:22:36
在componentDidMount()中添加this.manager = new BleManager();
发布于 2019-05-22 17:02:19
在项目文件夹中,执行以下操作:
npm install --save react-native-ble-plx
react-native link react-native-ble-plx按照这里的说明操作:https://github.com/Polidea/react-native-ble-plx这里还有一个示例项目:https://github.com/Cierpliwy/SensorTag
https://stackoverflow.com/questions/52294985
复制相似问题