1

I am new on React Native, could you helpe me? I have just installed the react-native-sensors(Yarn add --save react-native-sensors), then I imported on my project(import { Accelerometer } from "react-native-sensors";) but I receive this message "Native Modules for sensors not available. Did react-native link run successfully?"

I runned the command "react-native link react-native-sensors", but the error still persists =(

I am using the "react-native-sensors": "^5.1.5".

and this is my 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"
}
}

Thanks ! =)

Manoj Choudhari
  • 5,277
  • 2
  • 26
  • 37
  • Hey Daniel! Did you recompile the application after link? Sometimes an uninstall of your app from the device before running react-native link helps. – Daniel Schmidt Jan 23 '19 at 11:40

2 Answers2

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

Are you testing on iOS? If you are testing on iOS, you need to add this.

Option: With CocoaPods (iOS only)

Add the following to your Podfile and run $ pod install:

pod 'RNSensors', :path => '../node_modules/react-native-sensors'
hong developer
  • 13,291
  • 4
  • 38
  • 68
-1

Check your AVD for sensor capabilities and try to work with real devices. It woks fine for me with the given dependency version:- "react-native-sensors": "^5.1.8". Here is a little code snippet:- import { accelerometer, gyroscope, setUpdateIntervalForType, SensorTypes } from "react-native-sensors"; accelerometer.subscribe(({ x, y, z, timestamp }) => { console.log(X: ${ x }, Y:${y}, Z:${z}, timestamp: ${timestamp} )

Rohit
  • 3,314
  • 1
  • 13
  • 15