【问题标题】:detect shake event on iphone检测 iPhone 上的抖动事件
【发布时间】:2021-11-12 03:50:29
【问题描述】:

我正在尝试检测 iPhone 上的抖动事件。 shake.js library 不工作,将不胜感激任何帮助或其他解决方案。我也试过this,但没有运气。

function ClickRequestDeviceMotionEvent () {
window.DeviceMotionEvent.requestPermission()
.then(response => {
  if (response === 'granted') {
    window.addEventListener('devicemotion',
      () => { 
          //alert('DeviceMotion permissions granted.'); 
          
          var o = 0.6; // 0
          var myShakeEvent = new Shake ({
            threshold: 10, // 15. optional shake strength threshold
            timeout: 1000 // optional, determines the frequency of event generation
          });
          
          myShakeEvent.start(); // mobile, no ipad

          window.addEventListener('shake', shakeEventDidOccur, false);
          
          function shakeEventDidOccur() { // function to call when shake occurs
            alert('shake!');
          } 
      },
      (e) => { throw e }
  )} else {
    alert('DeviceMotion permissions not granted.')
  }
})
.catch(e => {
  alert(e)
})

}

【问题讨论】:

    标签: javascript ios


    【解决方案1】:

    从表面上看,这已经不可能了。

    Shake.js 已停产,因此不受支持。

    此外,Safari 不支持加速计、陀螺仪或 DeviceMotionEvent Web API,因此您的代码无法使用这些数据来做出反应。

    【讨论】:

    • 感谢您的回复!那么似乎没有其他方法可以使用 JS?
    • 似乎没有任何官方信息。最好看的地方是 the Mozilla docs,在 JS 或 Web API 下,但我找不到任何有用的东西。
    猜你喜欢
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多