Estoy tratando de detectar un evento de sacudida en el iPhone. La biblioteca shake.js no funciona, agradecería cualquier ayuda u otras soluciones. También he intentado esto pero sin suerte.
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) })}
Por lo que parece, esto ya no es posible.
Shake.js se suspendió, por lo que no es compatible.
Además, Safari no es compatible con el acelerómetro, el giroscopio o las API web de DeviceMotionEvent, por lo que estos datos simplemente no están disponibles para que su código reaccione.