cordova-plugin-shake icon indicating copy to clipboard operation
cordova-plugin-shake copied to clipboard

shake event not firing state change after state change shake is working in ionic can you please help me

Open mganigapeta opened this issue 8 years ago • 5 comments

this is my code:

if(!$window.localStorage.Shakecount){ $window.localStorage.setItem('Shakecount', 1); } if(!$window.localStorage.themecolor){ $window.localStorage.setItem('themecolor', "awesome_blue"); }

$scope.themecolor = $window.localStorage.getItem("themecolor");
var indexcount = $window.localStorage.getItem("Shakecount");



var onShake =  function() {
    alert("afterloadedok");
    switch(indexcount){
        case "1":
            var index = parseInt(indexcount) + 1;
            $scope.themecolor = "royal_pink";
            alert(index);
            alert($scope.themecolor);
            $window.localStorage.setItem('Shakecount', index);
            $window.localStorage.setItem('themecolor', $scope.themecolor);
            shake.stopWatch();
            $window.location.reload();
            break;
        case "2":
            var index = 1;
            $scope.themecolor = "awesome_blue";
            alert(index);
            alert($scope.themecolor);
            $window.localStorage.setItem('Shakecount', index);
            $window.localStorage.setItem('themecolor', $scope.themecolor);
            shake.stopWatch();
            $window.location.reload();
            break;

        default:
            index = 1;
            $scope.themecolor = "awesome_blue";
            alert(indexcount);
            alert($scope.themecolor);
            $window.localStorage.setItem('Shakecount', index);
            $window.localStorage.setItem('themecolor', $scope.themecolor);
            shake.stopWatch();
            $window.location.reload();
            break;
    }
}

if(window.shake) shake.startWatch(onShake,40);

mganigapeta avatar Aug 03 '17 08:08 mganigapeta

What is your problem? Do you see the first alert "afterloadedok" when you shake the device? If yes then there is something wrong in your function...

Ritzlgrmft avatar Aug 03 '17 16:08 Ritzlgrmft

first time not coming when click on any button or navigation then only you can able do shake event

mganigapeta avatar Aug 04 '17 04:08 mganigapeta

Do you wait for Cordova's deviceready event before calling shake.startWatch?

Ritzlgrmft avatar Aug 04 '17 07:08 Ritzlgrmft

yes i waited

mganigapeta avatar Aug 06 '17 04:08 mganigapeta

Have a look at https://github.com/Ritzlgrmft/ionic-feedback-sample, an app using the shake event

Ritzlgrmft avatar Dec 17 '17 17:12 Ritzlgrmft