2017-10-07 104 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。因爲很可能你以前的鏈接失敗了。