我想试一试来自Polidea的react原生的plx库。
https://github.com/Polidea/react-native-ble-plx
因此,我在终端中创建了一个新的应用程序,并安装了这个库。
create-react-native-app playground
npm install --save react-native-ble-plx
react-native link react-native-ble-plx然后运行npm start,然后运行i (用于在iOS模拟器中打开)
然后我得到了以下错误(在终端和模拟器中)
下面是App.js中的代码:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {BleManager} from 'react-native-ble-plx';
//importing BleManager without calling new BleManager() works
export default class App extends React.Component {
constructor(){
super();
this.manager = new BleManager();
}
//calling new BleManager() leads to error
render() {
return (
<View style={styles.container}>
<Text>nothing, just sucking errors</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});这是文件package.json
{
"name": "playground",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.5.0",
"jest-expo": "^21.0.2",
"react-test-renderer": "16.0.0-alpha.12"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^21.0.0",
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",
"react-native-ble-plx": "^0.6.3"
}
}我已经在找人帮忙了
npm -rm rf node_modules
npm install但没什么用。
这是我的系统信息:
macOS高塞拉 iMac (27英寸,2010年中部) 处理器2.8 GHz Intel Core i5 内存16 GB 1333 MHz DDR3
在我的iPhone(6s,10.3.1)中打开应用程序时,我也遇到了同样的错误(在从npm开始扫描终端中的QR代码之后)
其他没有反应本机plx库的应用程序正常工作。
期待着得到一些帮助。
提前谢谢。
弗兰克
发布于 2017-10-10 12:21:39
您已经使用创建-反应-本机-应用程序来创建您的反应本地项目。因此,您不能使用该项目的反应-本机-plx库。因为要访问蓝牙硬件,react本机plx包有一些本机代码分别用android和ios编写。
如果你想构建你的应用程序,你需要从创建-反应-本机应用程序中弹出,并使用Xcode和Android。
使用以下命令:--
npm install -g react-native-cli
npm run eject
react-native link react-native-ble-plx发布于 2019-02-04 18:09:15
我所做的是(在我开始之前,通过放弃git更改完全删除了ble)。
导航到/node_modules/react-native-ble-plx/ios/BleClient.xcodeproj和
https://stackoverflow.com/questions/46620192
复制相似问题