shake event not firing state change after state change shake is working in ionic can you please help me
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);
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...
first time not coming when click on any button or navigation then only you can able do shake event
Do you wait for Cordova's deviceready event before calling shake.startWatch?
yes i waited
Have a look at https://github.com/Ritzlgrmft/ionic-feedback-sample, an app using the shake event