{"action":"created","issue":{"url":"https://api.github.com/repos/nrswolf/cordova-plugin-push-notifications-status/issues/1","labels_url":"https://api.github.com/repos/nrswolf/cordova-plugin-push-notifications-status/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/nrswolf/cordova-plugin-push-notifications-status/issues/1/comments","events_url":"https://api.github.com/repos/nrswolf/cordova-plugin-push-notifications-status/issues/1/events","html_url":"https://github.com/nrswolf/cordova-plugin-push-notifications-status/issues/1","id":100652565,"number":1,"title":"Doesn't recognize state change after initial load (during run time)","user":{"login":"m0rganic","id":525275,"avatar_url":"https://avatars.githubusercontent.com/u/525275?v=3","gravatar_id":"","url":"https://api.github.com/users/m0rganic","html_url":"https://github.com/m0rganic","followers_url":"https://api.github.com/users/m0rganic/followers","following_url":"https://api.github.com/users/m0rganic/following{/other_user}","gists_url":"https://api.github.com/users/m0rganic/gists{/gist_id}","starred_url":"https://api.github.com/users/m0rganic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m0rganic/subscriptions","organizations_url":"https://api.github.com/users/m0rganic/orgs","repos_url":"https://api.github.com/users/m0rganic/repos","events_url":"https://api.github.com/users/m0rganic/events{/privacy}","received_events_url":"https://api.github.com/users/m0rganic/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-12T22:54:16Z","updated_at":"2015-08-20T20:59:43Z","closed_at":"2015-08-13T01:55:51Z","body":"@nrswolf Looks like a really useful plugin, thanks for your contribution!\r\n\r\nI'm building a push notifications settings screen in my app and would like to notify iOS users to head over to the Notification Center when the app detects push is disabled. \r\n\r\nI'm building it with ionic angular framework and have wrapped your cordova plugin with an angular service. The problematic behavior I'm seeing is that the plugin doesn't recognize state changes to the system notification setting unless I restart the app. \r\n\r\nAre you able to verify this works without app restarts?"},"comment":{"url":"https://api.github.com/repos/nrswolf/cordova-plugin-push-notifications-status/issues/comments/133169061","html_url":"https://github.com/nrswolf/cordova-plugin-push-notifications-status/issues/1#issuecomment-133169061","issue_url":"https://api.github.com/repos/nrswolf/cordova-plugin-push-notifications-status/issues/1","id":133169061,"user":{"login":"m0rganic","id":525275,"avatar_url":"https://avatars.githubusercontent.com/u/525275?v=3","gravatar_id":"","url":"https://api.github.com/users/m0rganic","html_url":"https://github.com/m0rganic","followers_url":"https://api.github.com/users/m0rganic/followers","following_url":"https://api.github.com/users/m0rganic/following{/other_user}","gists_url":"https://api.github.com/users/m0rganic/gists{/gist_id}","starred_url":"https://api.github.com/users/m0rganic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m0rganic/subscriptions","organizations_url":"https://api.github.com/users/m0rganic/orgs","repos_url":"https://api.github.com/users/m0rganic/repos","events_url":"https://api.github.com/users/m0rganic/events{/privacy}","received_events_url":"https://api.github.com/users/m0rganic/received_events","type":"User","site_admin":false},"created_at":"2015-08-20T20:59:43Z","updated_at":"2015-08-20T20:59:43Z","body":"I did something slightly more complex. This solution will allow you to limit running the interval call (which makes an expensive system call) to a small window when it's relevant to your app (i.e. on your settings screen, in-app push notifications setting screen, etc..).\r\n\r\nSince I'm developing on ionic so the interval api looks slightly different.. Also I'm wrapping your plugin with a service (see below) to return promises and cast the string result ('true' and 'false') to a boolean primitive.\r\n\r\n```javascript\r\nif (ionic.Platform.isIOS()) {\r\n  $scope.stopPushChecking = $interval(function() {\r\n    iOSPushNotificationStatus.checkIfEnabled()\r\n      .then(function(result) {\r\n        $scope.pushToggle.show = result; // pushEnabled should be boolean\r\n      }, function(error) {});\r\n  }, 1000);\r\n}\r\n```\r\n\r\nLater in that same controller where you need it, you can cancel the background interval thread, which is friendlier to the device.\r\n\r\n```javascript\r\n$scope.$on(\"$destroy\", function(event) {\r\n  if ($scope.stopPushChecking) {\r\n    $interval.cancel($scope.stopPushChecking);\r\n  }\r\n});\r\n```\r\n\r\nMy service that wraps this plugin with a promise and casts result from string to a boolean.\r\n\r\n```javascript\r\nangular.module('services', ['ionic', 'ngCordova'])\r\n\r\n.factory('iOSPushNotificationStatus', function($window, $q) {\r\n  var deferred = undefined;\r\n  var successHandler = function(response) {\r\n    if (typeof response === 'string') {\r\n      // coerce the string into a boolean\r\n      deferred.resolve(response == 'true' ? true : false);\r\n    } else if (typeof response === 'boolean') {\r\n      deferred.resolve(response);\r\n    } else {\r\n      errorHandler('successHandler couldnt parse type');\r\n    }\r\n  };\r\n  var errorHandler = function(error) {\r\n    deferred.reject(error);\r\n  };\r\n  return {\r\n    checkIfEnabled: function() {\r\n      deferred = $q.defer()\r\n      PushNotificationsStatus.isPushNotificationsEnabled(successHandler, errorHandler);\r\n      return deferred.promise;\r\n    }\r\n  }\r\n});\r\n\r\n``` "}}