I'm trying to get W3C Sensors API working inside my React Web App (Not React Native), basically I cannot find any reliable documentation for getting it to work using javascript, this is the code I produced so far:
import React, { Component } from "react";
export default class Postion extends Component {
state = {
message: "not supported",
};
componentDidMount() {
this.test();
}
test(){
if(window.Accelerometer){
this.setState({message:"supported"})
}
}
render() {
return <div>{this.state.message}</div>;
}
}
It displays "supported" on desktop browsers and "not supported" on all the mobile browser I tried so far, so my question is: how can I get data from the accelerometer using the sensors API (especially on mobile browsers)? I can even be done? Thanks.