From 4a04fa7250d6ab4c998549d691ade574069b9be2 Mon Sep 17 00:00:00 2001 From: mikkysati Date: Fri, 10 Apr 2015 13:05:57 +0530 Subject: [PATCH] Only one time registarion Creating a variable in local storage, so app won't register again after successful registration. --- www/js/controllers.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/www/js/controllers.js b/www/js/controllers.js index fd7176d..c79cd25 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -9,7 +9,12 @@ app.controller('AppCtrl', function($scope, $cordovaPush, $cordovaDialogs, $cordo // call to register automatically upon device ready ionPlatform.ready.then(function (device) { - $scope.register(); + if (window.localStorage['regid'] !== "true") { + $scope.register(); + console.log("regid is not true so registering the device for push notification"); + } else { + console.log("regid is true so need for registering"); + } }); @@ -126,9 +131,12 @@ app.controller('AppCtrl', function($scope, $cordovaPush, $cordovaDialogs, $cordo $http.post('http://192.168.1.16:8000/subscribe', JSON.stringify(user)) .success(function (data, status) { console.log("Token stored, device is successfully subscribed to receive push notifications."); + + window.localStorage['regid'] = true; }) .error(function (data, status) { console.log("Error storing device token." + data + " " + status) + $cordovaToast.showLongBottom('The app is unable to register for push notification, try again later by repopening the app'); } ); }