{"_id":"55a90b6bcf45e1390093f2b8","parentDoc":null,"__v":21,"project":"5540ce1b31827a0d007ab1cc","category":{"_id":"55b9ffca04775a2f00628075","project":"5540ce1b31827a0d007ab1cc","pages":[],"__v":0,"version":"5540ce1c31827a0d007ab1cf","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-30T10:43:22.648Z","from_sync":false,"order":22,"slug":"phonegap-build","title":"Phonegap Build"},"user":"55a5003a750a9a23005332b6","version":{"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","__v":31,"createdAt":"2015-04-29T12:27:08.390Z","releaseDate":"2015-04-29T12:27:08.390Z","categories":["5540ce1c31827a0d007ab1d0","5540d91bbb9e762d00f594ad","5540e5f131827a0d007ab212","5540e5febb9e762d00f594d3","5540e61331827a0d007ab213","5540e6195cf9682100d61afa","5540e62631827a0d007ab214","5540e63031827a0d007ab215","5540e63531827a0d007ab216","5540e63e5cf9682100d61afc","5540e6445cf9682100d61afd","5540e64a5cf9682100d61afe","55a4ff5b2e70c0250038050f","55acb28318eefd0d0071d504","55ae1abe8576b92300291c80","55ae453ef302af23000ac109","55af586d555b900d0036d296","55af91dac8a85321007a53c3","55b9fee204775a2f00628071","55b9ff0e04775a2f00628072","55b9ff4604775a2f00628073","55b9ff5fd72d1e1900276a38","55b9ff7f04775a2f00628074","55b9ff90eb08801900f833e5","55b9ffa5d72d1e1900276a39","55b9ffca04775a2f00628075","55b9fffdd72d1e1900276a3a","56bc2f033ee9e70d008b46af","56c2f6efbbf9ec2d00e0fe4f","57595bbb18760817001e8bbe","57d8d9793916800e003dde53"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":["562687ecb1c2630d00b112ab"],"next":{"pages":[],"description":""},"createdAt":"2015-07-17T14:04:27.094Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Supports iOS, Android, Windows Phone\"\n}\n[/block]\n[**Download Sample**](https://github.com/Pushwoosh/phonegap-3-sample-app)\n[**Plugin API Docs**](http://docs.pushwoosh.com/docs/cordova-api-reference)\n\nTo add Pushwoosh plugin to your PhoneGap Build project:\n\n**1.** Add the plugin in **www/config.xml**:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<gap:plugin name=\\\"pushwoosh-pgb-plugin\\\" source=\\\"npm\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n**2.** In **www/config.xml** allow access to ***.pushwoosh.com**:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<access origin=\\\"*\\\"/> <!-- allow all pages, use for development -->\\n<access origin=\\\"*.pushwoosh.com\\\"/> <!-- allow pushwoosh service -->\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n**3.** In **www/config.xml** use gradle build tool:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<preference name=\\\"android-build-tool\\\" value=\\\"gradle\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n**4.** Add Pushwoosh initialization function to your **javascript file**:\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"Do not forget to put the correct Pushwoosh App ID.\\nFor **Android** put the correct Google Project Number as well.\",\n  \"title\": \"Important\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"function initPushwoosh() {\\n  var pushwoosh = cordova.require(\\\"pushwoosh-cordova-plugin.PushNotification\\\");\\n\\n  // Should be called before pushwoosh.onDeviceReady\\n  document.addEventListener('push-notification', function(event) {\\n    var notification = event.notification;\\n    // handle push open here\\n  });\\n  \\n  // Initialize Pushwoosh. This will trigger all pending push notifications on start.\\n  pushwoosh.onDeviceReady({\\n    appid: \\\"PUSHWOOSH_APP_ID\\\",\\n    projectid: \\\"GOOGLE_PROJECT_NUMBER\\\",\\n    serviceName: \\\"MPNS_SERVICE_NAME\\\"\\n  });\\n}\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIn **onDeviceReady** function add `initPushwoosh();`\n\nExample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bindEvents: function() {\\n        document.addEventListener('deviceready', this.onDeviceReady, false);\\n    },\\n    // deviceready Event Handler\\n    //\\n    // 'this' covers the event. To call 'receivedEvent' function, explicitly call 'app.receivedEvent(...);'\\n    onDeviceReady: function() {\\n        app.receivedEvent('deviceready');\\n        initPushwoosh();\\n    },\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**5.** Registering and handling push notifications\n\nTo register for push notifications call\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pushwoosh.registerDevice(\\n  function(status) {\\n    var pushToken = status.pushToken;\\n      // handle successful registration here\\n  },\\n  function(status) {\\n    // handle registration error here\\n  }\\n);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nFor handling notificatios see the following snippet of code in **initPushwoosh** function\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// should be called before pushwoosh.onDeviceReady\\ndocument.addEventListener('push-notification', function(event) {\\n  var notification = event.notification;\\n  // handle push open here\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"Integrating Pushwoosh SDK into your PhoneGap Build project","slug":"phonegap-build","type":"basic","title":"PhoneGap Build"}

PhoneGap Build

Integrating Pushwoosh SDK into your PhoneGap Build project

[block:callout] { "type": "success", "title": "Supports iOS, Android, Windows Phone" } [/block] [**Download Sample**](https://github.com/Pushwoosh/phonegap-3-sample-app) [**Plugin API Docs**](http://docs.pushwoosh.com/docs/cordova-api-reference) To add Pushwoosh plugin to your PhoneGap Build project: **1.** Add the plugin in **www/config.xml**: [block:code] { "codes": [ { "code": "<gap:plugin name=\"pushwoosh-pgb-plugin\" source=\"npm\" />", "language": "xml" } ] } [/block] **2.** In **www/config.xml** allow access to ***.pushwoosh.com**: [block:code] { "codes": [ { "code": "<access origin=\"*\"/> <!-- allow all pages, use for development -->\n<access origin=\"*.pushwoosh.com\"/> <!-- allow pushwoosh service -->", "language": "xml" } ] } [/block] **3.** In **www/config.xml** use gradle build tool: [block:code] { "codes": [ { "code": "<preference name=\"android-build-tool\" value=\"gradle\" />", "language": "xml" } ] } [/block] **4.** Add Pushwoosh initialization function to your **javascript file**: [block:callout] { "type": "warning", "body": "Do not forget to put the correct Pushwoosh App ID.\nFor **Android** put the correct Google Project Number as well.", "title": "Important" } [/block] [block:code] { "codes": [ { "code": "function initPushwoosh() {\n var pushwoosh = cordova.require(\"pushwoosh-cordova-plugin.PushNotification\");\n\n // Should be called before pushwoosh.onDeviceReady\n document.addEventListener('push-notification', function(event) {\n var notification = event.notification;\n // handle push open here\n });\n \n // Initialize Pushwoosh. This will trigger all pending push notifications on start.\n pushwoosh.onDeviceReady({\n appid: \"PUSHWOOSH_APP_ID\",\n projectid: \"GOOGLE_PROJECT_NUMBER\",\n serviceName: \"MPNS_SERVICE_NAME\"\n });\n}\n", "language": "javascript" } ] } [/block] In **onDeviceReady** function add `initPushwoosh();` Example: [block:code] { "codes": [ { "code": "bindEvents: function() {\n document.addEventListener('deviceready', this.onDeviceReady, false);\n },\n // deviceready Event Handler\n //\n // 'this' covers the event. To call 'receivedEvent' function, explicitly call 'app.receivedEvent(...);'\n onDeviceReady: function() {\n app.receivedEvent('deviceready');\n initPushwoosh();\n },", "language": "javascript" } ] } [/block] **5.** Registering and handling push notifications To register for push notifications call [block:code] { "codes": [ { "code": "pushwoosh.registerDevice(\n function(status) {\n var pushToken = status.pushToken;\n // handle successful registration here\n },\n function(status) {\n // handle registration error here\n }\n);", "language": "javascript" } ] } [/block] For handling notificatios see the following snippet of code in **initPushwoosh** function [block:code] { "codes": [ { "code": "// should be called before pushwoosh.onDeviceReady\ndocument.addEventListener('push-notification', function(event) {\n var notification = event.notification;\n // handle push open here\n});", "language": "javascript" } ] } [/block]