首页 > 解决方案 > React Native null 不是对象(评估'NativeBeaconBroadcast.checkTransmissionSupported')

问题描述

我正在尝试使用此库https://github.com/williamtran29/react-native-ibeacon-simulator在本机反应中构建一个应用程序,它应该在广播中传输 BLE 数据包,充当信标(或 iBeacon)。

我试图做的是仅在中构建一个幼稚的示例,App.js但它不起作用。

import { StatusBar } from 'expo-status-bar';
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import BeaconBroadcast from 'react-native-ibeacon-simulator';

export default class App extends Component {
  constructor(props) {
    super(props);
    BeaconBroadcast.checkTransmissionSupported()
    .then(() => {
      BeaconBroadcast.stopAdvertisingBeacon();
      BeaconBroadcast.startAdvertisingBeaconWithString("8f2f6604-7160-43b2-82b2-f1c44ae8b21b", 0, 0, 0);
    })
    .catch((e) => {
      console.error(e);
    })
  }

  render() {
    return (
      <View style={styles.container}>
        <Text>Open up App.js to start working on your app!</Text>
        <StatusBar style="auto" />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

但是,如果我尝试运行此代码(使用 expo),我会得到这个

null is not an object (evaluating 'NativeBeaconBroadcast.checkTransmissionSupported')
- node_modules/react-native-ibeacon-simulator/index.android.js:15:23 in Promise$argument_0
- node_modules/react-native/node_modules/promise/setimmediate/core.js:45:6 in tryCallTwo
- node_modules/react-native/node_modules/promise/setimmediate/core.js:200:22 in doResolve
- node_modules/react-native/node_modules/promise/setimmediate/core.js:66:11 in Promise
- node_modules/react-native-ibeacon-simulator/index.android.js:14:2 in <global>
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:7655:17 in constructClassInstance
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:12377:26 in updateClassComponent
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:19181:22 in beginWork$1
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:18085:22 in performUnitOfWork
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:18013:38 in workLoopSync
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:17977:18 in renderRootSync
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:17674:33 in performSyncWorkOnRoot
* [native code]:null in performSyncWorkOnRoot
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5321:31 in runWithPriority$argument_1
- node_modules/scheduler/cjs/scheduler.development.js:653:23 in unstable_runWithPriority
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5316:21 in flushSyncCallbackQueueImpl
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5304:28 in flushSyncCallbackQueue
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:17741:26 in flushSync
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:6154:13 in scheduleRefresh
- node_modules/react-refresh/cjs/react-refresh-runtime.development.js:218:8 in mountedRoots.forEach$argument_0
* [native code]:null in forEach
- node_modules/react-refresh/cjs/react-refresh-runtime.development.js:210:4 in performReactRefresh
- node_modules/react-native/Libraries/Core/setUpReactRefresh.js:43:6 in Refresh.performReactRefresh
- node_modules/metro/src/lib/polyfills/require.js:627:10 in setTimeout$argument_0
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:383:16 in callTimers
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

标签: javascriptnode.jsreact-nativenpmbluetooth-lowenergy

解决方案


推荐阅读