反应本地的,BleManager“本机模块不能为空”

问题描述 投票:1回答:2

我想尝试从Polidea的反应本地-BLE-PLX库

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(在iPhone模拟器开口)

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

  • 本机模块不能为空
  • node_modules /反应天然/ node_modules / FBJS / LIB / invariant.js:44:24在不变
  • node_modules /反应天然/库/ EventEmitter / NativeEventEmitter.js:31:16在NativeEventEmitter
  • node_modules /反应天然-BLE-PLX / SRC / BleManager.js:52:25在BleManager
  • App.js:8:19应用程序
  • 在33:node_modules /反应天然/库/渲染器/ ReactNativeStack-dev.js:1679
  • 在measureLifeCyclePerf 15:node_modules /反应天然/库/渲染器/ ReactNativeStack-dev.js:1610
  • ...从框架内部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.8GHz的英特尔酷睿i5

存储器16 GB 1333兆赫DDR3

在我的iPhone打开时,应用程序(6S,10.3.1)(NPM从开始扫描QR码在终端后)我也得到了同样的错误

其他应用程序没有反应母语-BLE-PLX库工作正常。

期待收到一些帮助。 提前致谢。 坦率

react-native bluetooth-lowenergy expo
2个回答
0
投票

你已经使用创建反应的原生应用程序内创建你的阵营本地项目。所以你不能使用反应母语-BLE-PLX库项目。由于访问蓝牙硬件,反应母语-BLE-PLX包有写在Android和iOS seperately一些本地代码。

如果你想建立自己的应用程序,你需要从建立反应的原生应用程序内弹出,并使用Xcode和Android的工作室。

使用下面的命令: -

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

0
投票

我所做的是(后丢弃的git变化,我开始之前完全去除BLE-PLX)

导航到/node_modules/react-native-ble-plx/ios/BleClient.xcodeproj和

  1. 我把那进库文件夹中的项目导航
  2. 然后我去我的目标 - >构建阶段 - >链接二进制与图书馆和添加libBleClient.a
© www.soinside.com 2019 - 2024. All rights reserved.