【问题标题】:React Native BluetoothManager NativeModules NULLReact Native BluetoothManager NativeModules NULL
【发布时间】:2020-05-21 09:10:14
【问题描述】:

我正在尝试在 React Native 中使用 BluetoothManager,已经完成了这些步骤:

  • 我使用react-native init MyProject 进行了全新安装
  • 在 App.js 中导入 NativeMoludes:import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, NativeModules } from 'react-native';
  • 初始化蓝牙管理器:const { BluetoothManager} = NativeModules;
  • return(...) 之前执行alert(BluetoothManager);

但它总是提示空值。我是否错过了 RN 安装或导入中的某些内容? 我正在使用 React Native v.0.62.2。请指教。

【问题讨论】:

    标签: react-native


    【解决方案1】:

    我建议在 react-native 中使用 https://github.com/innoveit/react-native-ble-managerhttps://github.com/Polidea/react-native-ble-plx 来处理所有与蓝牙相关的内容

    【讨论】:

      【解决方案2】:

      你是not importing BluetoothManager properly,你必须安装这个模块,

      https://github.com/innoveit/react-native-ble-manager

      将该模块(如果自动链接不可用,但在 ios 的情况下为 pod install)链接到您的项目,然后像下面这样导入

      import BleManager from 'react-native-ble-manager';
      

      这里还有一个导入和使用的例子。

      https://github.com/innoveit/react-native-ble-manager/blob/master/example/App.js

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-10-08
        • 2017-05-02
        • 2018-06-25
        • 2021-06-09
        • 2018-04-30
        • 1970-01-01
        • 2019-12-29
        相关资源
        最近更新 更多