2017-10-07 103 views
1

我想从Polidea试用反应母语-BLE-PLX库阵营本地的,BleManager“本机模块不能为空”

https://github.com/Polidea/react-native-ble-plx

所以我创建了终端新的应用和安装通过Polidea说明过的文库

create-react-native-app playground 

npm install --save react-native-ble-plx 

react-native link react-native-ble-plx 

我然后跑npm start然后i(用于在IOS模拟器开口)

,然后我得到了以下错误(在终端和在模拟器)

  • 本机模块不能为空
  • node_modules /反应天然/ node_modules/FBJS/LIB/invariant.js:44 :31:16在NativeEventEmitter
  • node_modules /反应天然-BLE-PLX/SRC/BleManager.js:52:25在BleManager在不变
  • node_modules /反应天然/库/ EventEmitter/NativeEventEmitter.js 24
  • App.js:8:在应用
  • node_modules /反应天然/库/渲染器/ ReactNativeStack-dev.js:1679:33
  • node_modules /反应天然/库/渲染器/ ReactNativeStack-dev.js:1610:在measureLifeCyclePerf
  • 15。 ..从框架52多个堆栈帧内部构件

这里是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英特尔酷睿i5

内存16 GB 1333 MHz DDR3

我也拿到了山姆(从NPM开始扫描的QR码在终端之后)开在我的iPhone应用程式(6S,10.3.1)当E错误

没有反应天然-BLE-PLX库的正常工作的其他应用程序。

期待收到一些帮助。
在此先感谢。
Frank

回答

0

您已经使用create-react-native-app来创建您的React Native项目。所以你不能在这个项目中使用react-native-ble-plx库。由于访问蓝牙硬件,react-native-ble-plx软件包有一些本机代码,分别用android和ios编写。

如果您想构建应用程序,则需要从create-react-native-app中弹出,并使用Xcode和Android Studio。

使用下面的命令: -

npm install -g react-native-cli 
npm run eject 
react-native link react-native-ble-plx 
  • 第一个命令是安装反应母语-CLI全球
  • 第二个命令是你的项目从世博会项目转换为普通阵营本地项目
  • 第三条命令是链接react-native-ble-plx。因为很可能你以前的链接失败了。