我是React本机框架的新手。我已经使用“ create-react-native-app AwesomeProject”创建了应用。我想在项目中使用BLE,所以我安装了'react-native-ble-plx'模块,但是当我创建BleManager的实例时,它将引发错误TypeError:无法读取未定义的属性'createClient'。为什么会引发此错误?我的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"
}
});
答案 0 :(得分:0)
在componentDidMount()中添加this.manager = new BleManager();
答案 1 :(得分:0)
在您的项目文件夹中,执行以下操作:
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