{"action":"created","issue":{"url":"https://api.github.com/repos/driftyco/ionic-platform-web-client/issues/78","repository_url":"https://api.github.com/repos/driftyco/ionic-platform-web-client","labels_url":"https://api.github.com/repos/driftyco/ionic-platform-web-client/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/driftyco/ionic-platform-web-client/issues/78/comments","events_url":"https://api.github.com/repos/driftyco/ionic-platform-web-client/issues/78/events","html_url":"https://github.com/driftyco/ionic-platform-web-client/issues/78","id":142743555,"number":78,"title":"Device receives notification, but onNotification callback is only fired when app is in foreground","user":{"login":"danielslz","id":5704,"avatar_url":"https://avatars.githubusercontent.com/u/5704?v=3","gravatar_id":"","url":"https://api.github.com/users/danielslz","html_url":"https://github.com/danielslz","followers_url":"https://api.github.com/users/danielslz/followers","following_url":"https://api.github.com/users/danielslz/following{/other_user}","gists_url":"https://api.github.com/users/danielslz/gists{/gist_id}","starred_url":"https://api.github.com/users/danielslz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielslz/subscriptions","organizations_url":"https://api.github.com/users/danielslz/orgs","repos_url":"https://api.github.com/users/danielslz/repos","events_url":"https://api.github.com/users/danielslz/events{/privacy}","received_events_url":"https://api.github.com/users/danielslz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-03-22T18:48:44Z","updated_at":"2016-04-01T10:57:22Z","closed_at":"2016-03-31T21:18:02Z","body":"So, what i did was:\r\n\r\n1 - create a project:\r\n`ionic start myPushApp tabs`\r\n\r\n2 - Initialized ionic io:\r\n`ionic io init`\r\n\r\n3 - Setup GCM according to [this guide](http://docs.ionic.io/v2.0.0-beta/docs/android-push-profiles)\r\n\r\n4 - Setup GCM key\r\n`ionic config set gcm_key <my-gcm-project-number>`\r\n\r\n5 - On Ionic.io dashboard, create the certificate and setup the GCM API Key\r\n\r\n6 - Install ionic-platform-web-client\r\n`ionic add ionic-platform-web-client`\r\n\r\n7 - Install phonegap-plugin-push\r\n`ionic plugin add phonegap-plugin-push --variable SENDER_ID=\"MY_GCM_PROJECT_NUMBER\"`\r\n\r\n8 - Set dev_push to false\r\n`ionic config set dev_push false`\r\n\r\n9 - Add push code inside run block in app.js\r\n```\r\nvar push = new Ionic.Push({\r\n  \"debug\": true,\r\n  'onNotification': function (notification) {\r\n    console.log(notification);\r\n    alert('onNotification fired!');\r\n  },\r\n  'onRegister': function () {\r\n    alert('onRegister fired!');\r\n  }\r\n});\r\n\r\npush.register(function(token) {\r\n  console.log(\"Device token:\",token.token);\r\n  push.saveToken(token);  // persist the token in the Ionic Platform\r\n});\r\n```\r\n10 - Add Android platform\r\n`ionic platform add android`\r\n\r\n11 - Run app in a device\r\n`ionic run`\r\n\r\n12 - Send a push\r\n```\r\ncurl -X POST -H \"Authorization: Bearer MY_API_TOKEN\" -H \"Content-Type: application/json\" -d '{\r\n    \"tokens\": [\"MY_DEVICE_TOKEN\"],\r\n    \"profile\": \"test\",\r\n    \"notification\": {\r\n        \"message\": \"Hello World!\"\r\n    }\r\n}' \"https://api.ionic.io/push/notifications\"\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/driftyco/ionic-platform-web-client/issues/comments/204348609","html_url":"https://github.com/driftyco/ionic-platform-web-client/issues/78#issuecomment-204348609","issue_url":"https://api.github.com/repos/driftyco/ionic-platform-web-client/issues/78","id":204348609,"user":{"login":"danielslz","id":5704,"avatar_url":"https://avatars.githubusercontent.com/u/5704?v=3","gravatar_id":"","url":"https://api.github.com/users/danielslz","html_url":"https://github.com/danielslz","followers_url":"https://api.github.com/users/danielslz/followers","following_url":"https://api.github.com/users/danielslz/following{/other_user}","gists_url":"https://api.github.com/users/danielslz/gists{/gist_id}","starred_url":"https://api.github.com/users/danielslz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielslz/subscriptions","organizations_url":"https://api.github.com/users/danielslz/orgs","repos_url":"https://api.github.com/users/danielslz/repos","events_url":"https://api.github.com/users/danielslz/events{/privacy}","received_events_url":"https://api.github.com/users/danielslz/received_events","type":"User","site_admin":false},"created_at":"2016-04-01T10:57:22Z","updated_at":"2016-04-01T10:57:22Z","body":"It's ok now, work's fine, thank you guys!"}}