openDeviceMotionListening = () => {
return new Promise(resolve => {
const getAlpha = ({ alpha }) => {
this.closeDeviceMotionListening()
resolve(alpha)
}
Taro.startDeviceMotionListening()
Taro.onDeviceMotionChange(getAlpha)
})
}
/**
* @description: 关闭获取用户手机设备方向
* @return {*}
*/
closeDeviceMotionListening = () => {
// Taro.offDeviceMotionChange(); // TODO: 此方法报错
Taro.stopDeviceMotionListening()
}
const alpha = await openDeviceMotionListening ()