错误:传感器的本机模块不可用。 react-native链接是否成功运行?

时间:2019-01-17 17:16:48

标签: react-native react-native-sensors

我是React Native的新手,您能帮我吗?我刚刚安装了react-native-sensors(纱线添加--save react-native-sensors),然后将其导入到我的项目中(从“ react-native-sensors”中导入{Accelerometer};),但我收到此消息“传感器的本机模块不可用。react-native链接是否成功运行?”

我运行了命令“ react-native link react-native-sensors”,但是错误 仍然存在=(

我正在使用“ react-native-sensors”:“ ^ 5.1.5”。

这是我的package.json

{
"name": "tcc_mobile",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"lodash": "^4.17.11",
"react": "16.6.1",
"react-native": "0.57.7",
"react-native-gesture-handler": "^1.0.10",
"react-native-sensors": "^5.1.5",
"react-navigation": "^3.0.8",
"rxjs": "^6.3.3"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.48.5",
"react-test-renderer": "16.6.1"
},
"jest": {
"preset": "react-native"
}
}

谢谢! =)

3 个答案:

答案 0 :(得分:0)

  1. $ npm install react-native-sensors --save or Yarn add
  2. $ react-native link react-native-sensors

您要在iOS上进行测试吗?如果要在iOS上进行测试,则需要添加它。

  

选项:使用CocoaPods(仅适用于iOS)

将以下内容添加到您的Podfile中并运行$ pod install:

pod 'RNSensors', :path => '../node_modules/react-native-sensors'

答案 1 :(得分:-1)

检查您的AVD的传感器功能,然后尝试在实际设备上使用。对于给定的依赖版本,它对我来说还不错:-  import { accelerometer, gyroscope, setUpdateIntervalForType, SensorTypes } from "react-native-sensors"; accelerometer.subscribe(({ x, y, z, timestamp }) => { console.log(。这是一个小代码段: ) X:$ {x},Y:$ {y},Z:$ {z},时间戳:$ {timestamp} Project1: --Repository 1 --Repository 2 --Repository 3 -- -- --Repository 8

答案 2 :(得分:-1)

其背后的原因可以在以下帖子中找到:

Native modules for sensors not available. Did react-native link run successfully?

也就是说,如果您使用EXPO。这就是我正在使用的。