leecrossley / cordova-plugin-shake

Cordova / PhoneGap Plugin to detect when a physical device performs a shake gesture
http://ilee.co.uk
92 stars 33 forks source link

Shake event is fired twice every time it fires #11

Closed confile closed 9 years ago

confile commented 9 years ago

Shake event is fired twice every time it fires. Even increasing the sensitivity I was not able to reduce the number of times the shake method is called.

Whenever I shake my iPhone 5 iOS 7.2.2 the callback is called twice.

leecrossley commented 9 years ago

Do you have a sample project you can reference?

leecrossley commented 9 years ago

Closing due to inactivity

dandv commented 9 years ago

I've also experienced the double shake problem on Android. Here's a project that reproduces the issue, along with using debounce to work around it - https://github.com/dandv/meteor-shake/blob/master/example/client/example.js#L6

Note that @alexgibson's shake.js (shake detection for mobile browsers using the devicemotion API) also handles this problem by using a timeout (defaulting to 1000ms).

mhoelter commented 9 years ago

I'm also running into this issue. For what it's worth, here is the code I'm using:

// Device Ready
document.addEventListener("deviceready", function() {

    // http://plugreg.com/plugin/leecrossley/cordova-plugin-shake-detection
    var onShake = function() {
        console.log("Shake!");
        nextLevel();
    };

    // Start watching for shake gestures and call "onShake"
    // with a shake sensitivity of 40 (optional, default 30)
    shake.startWatch(onShake, 30);
});