I'm trying to detect a shake event on iPhone. shake.js library is not working, would appreciate any help or other solutions. I've also tried this but no luck.
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)
})
}
By the looks of it, this isn't possible anymore.
Shake.js was discontinued so is not supported.
Also, Safari does not support the Accelerometer, Gyroscope or the DeviceMotionEvent web API's, so this data is just not available for your code to react to.