解决ios13摇一摇不能触发

代码如下

permissionForShake() {
      if (typeof DeviceMotionEvent.requestPermission === 'function') {
        DeviceMotionEvent.requestPermission()
          .then(permissionState => {
            if (permissionState === 'granted') {
              window.addEventListener('devicemotion', () => {})
            }
          })
          .catch(err => {
            console.log(err)
          });
      } else {
        console.log(22222)
        // ios其他系统可以不通过请求直接摇一摇
      }
    }
permissionForShake这个方法必须需要用户点击才能触发,js代码不能触发
原文地址:https://www.cnblogs.com/huangguofeng/p/13268405.html