【发布时间】:2020-05-10 12:51:03
【问题描述】:
我正在尝试让 W3C Sensors API 在我的 React Web 应用程序(不是 React Native)中工作,基本上我找不到任何可靠的文档来让它使用 javascript 工作,这是我到目前为止生成的代码:
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>;
}
}
它在桌面浏览器上显示“支持”,而在我迄今为止尝试的所有移动浏览器上显示“不支持”,所以我的问题是:如何使用传感器 API(尤其是在移动浏览器上)从加速度计获取数据?我什至可以完成?谢谢。
【问题讨论】:
标签: reactjs w3c w3c-geolocation