{"action":"created","issue":{"url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/798","repository_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push","labels_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/798/labels{/name}","comments_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/798/comments","events_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/798/events","html_url":"https://github.com/phonegap/phonegap-plugin-push/issues/798","id":147640997,"number":798,"title":"Plugin init ","user":{"login":"harslanhafeez","id":12417715,"avatar_url":"https://avatars.githubusercontent.com/u/12417715?v=3","gravatar_id":"","url":"https://api.github.com/users/harslanhafeez","html_url":"https://github.com/harslanhafeez","followers_url":"https://api.github.com/users/harslanhafeez/followers","following_url":"https://api.github.com/users/harslanhafeez/following{/other_user}","gists_url":"https://api.github.com/users/harslanhafeez/gists{/gist_id}","starred_url":"https://api.github.com/users/harslanhafeez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harslanhafeez/subscriptions","organizations_url":"https://api.github.com/users/harslanhafeez/orgs","repos_url":"https://api.github.com/users/harslanhafeez/repos","events_url":"https://api.github.com/users/harslanhafeez/events{/privacy}","received_events_url":"https://api.github.com/users/harslanhafeez/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-12T05:56:58Z","updated_at":"2016-04-12T11:23:58Z","closed_at":"2016-04-12T11:23:58Z","body":"I could not understand init problem.\r\nMy app behaves like\r\nlogin > init plugin and register tokens > feed page\r\nnow whenever app re-open\r\nindex.html >check if access_token is valid > feed page\r\n\r\nAfter successful login to app I init the plugin and register GCM/APNS token in my server and assign it access_token from server.\r\nwhenever app  re-open it first check if access_token is still valid in index.html page and then goes to news feed page. I can not understand after initiating plugin in login page should i re-initiate this in index.html page or in feed page or in all pages? So whenever notification arrive it should listen for it...\r\nMy notification.js is:\r\n\r\n```\r\n(function($) {\r\n\t  var self;\r\n\t  var notification = function (){\r\n\t  \"use strict\";\r\n\t  self = notification;\r\n  };\r\n  \r\n  notification.prototype={\r\n\tinit:function (done){\r\n\t\t  document.addEventListener(\"deviceready\", function(){\r\n\t  self.push = PushNotification.init({\r\n\t\t\t  \"android\": {\r\n\t\t\t\t  \"senderID\": \"123456789\",\r\n\t\t\t\t  \"vibrate\":\"true\",\r\n\t\t\t\t  \"sound\":\"false\",\r\n\t\t\t\t  \"clearNotifications\":\"false\",\r\n\t\t\t  }\r\n\t\t  });\r\n\tself.push.on('registration', function(data) {\r\n\t\t\t  done(data.registrationId);\r\n\t\t  });\r\n\t\t  self.push.on('notification', function(data) {\r\n\t\t\t  var id,tag ,noid; \r\n\t\t\t  try{\r\n\t\t\t\t  id = data['additionalData']['source_id'];\r\n\t\t\t\t  tag = data['additionalData']['tag'];\r\n\t\t\t\t  noid = data['additionalData']['noid'];\r\n\t\t\t}\r\n\t\t\t  catch(ex){alert(ex);}\r\n\t\t\t  if(window.location.pathname == \"/android_asset/www/index.html\" || window.location.pathname == \"/android_asset/www/SignIn.html\")\r\n\t\t\t  {\r\n\t\t\t  \t\twindow.location.replace('notification/postPage.html?source_id='+id+'&tag='+tag);\r\n\t\t\t  }\r\n\t\t\t else\r\n\t\t\t  \twindow.location.replace('../notification/postPage.html?source_id='+id+'&tag='+tag);\r\n\t\t\t  if(data.additionalData.coldstart)\r\n\t\t\t\t  alert('yes it is cold start');\r\n\t\t\t  self.push.finish(function () {\r\n\t\t\t\t  \r\n\t\t\t\t console.log('finish successfully called');\r\n\t\t\t  });\r\n\t\t  });\r\n\t\t  \r\n\t\t  \r\n\t\t\tself.push.setApplicationIconBadgeNumber(function() {\r\n\t\t\t\tconsole.log('success');\r\n\t\t\t}, function(e) {\r\n\t\t\t\tconsole.log('error');\r\n\t\t\t}, 2);\r\n  \r\n\t\t  self.push.on('error', function(e) {\r\n\t\t\t  self.init();\r\n\t\t  });\r\n\t  },false);\r\n  }\r\n  };\r\n  $.notifications = new notification();\r\n  \r\n\t})(jQuery);\r\n  \r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/comments/208854166","html_url":"https://github.com/phonegap/phonegap-plugin-push/issues/798#issuecomment-208854166","issue_url":"https://api.github.com/repos/phonegap/phonegap-plugin-push/issues/798","id":208854166,"user":{"login":"macdonst","id":353180,"avatar_url":"https://avatars.githubusercontent.com/u/353180?v=3","gravatar_id":"","url":"https://api.github.com/users/macdonst","html_url":"https://github.com/macdonst","followers_url":"https://api.github.com/users/macdonst/followers","following_url":"https://api.github.com/users/macdonst/following{/other_user}","gists_url":"https://api.github.com/users/macdonst/gists{/gist_id}","starred_url":"https://api.github.com/users/macdonst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/macdonst/subscriptions","organizations_url":"https://api.github.com/users/macdonst/orgs","repos_url":"https://api.github.com/users/macdonst/repos","events_url":"https://api.github.com/users/macdonst/events{/privacy}","received_events_url":"https://api.github.com/users/macdonst/received_events","type":"User","site_admin":false},"created_at":"2016-04-12T11:23:58Z","updated_at":"2016-04-12T11:23:58Z","body":"@harslanhafeez call init every time you start your app. There is always a chance the registration ID changed. Sometimes APNS/GCM will invalidate ID's.\r\n\r\nIf you call PushNotification.init on the login.html page and then you move to feed.html page all of your JS will be unloaded and you'll need to call PushNotification.init again."}}