{"_id":"55a3c52253611017004386bd","project":"5540ce1b31827a0d007ab1cc","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"},"__v":45,"user":"5540cdbf5cf9682100d61a97","category":{"_id":"55b9ffa5d72d1e1900276a39","__v":0,"project":"5540ce1b31827a0d007ab1cc","version":"5540ce1c31827a0d007ab1cf","pages":[],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-30T10:42:45.253Z","from_sync":false,"order":15,"slug":"cordova-phonegap","title":"Cordova (PhoneGap)"},"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-13T14:03:14.795Z","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, Windows\"\n}\n[/block]\n[**Download SDK**](https://github.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin)\n[**Download Sample**](https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample)\n[**Plugin API Docs**](http://docs.pushwoosh.com/docs/cordova-api-reference) \n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"iOS Simulator can neither subscribe nor receive push notifications. Android and Windows Phone emulator will work.\",\n  \"title\": \"Note:\"\n}\n[/block]\nTo integrate Pushwoosh with your Cordova application, follow these simple steps:\n\n**1.** Install the Plugin source code into your app:\n\n  * For Phonegap: `phonegap plugin add pushwoosh-cordova-plugin`\n  * For Cordova: `cordova plugin add pushwoosh-cordova-plugin`\n  * For Ionic: `ionic plugin add pushwoosh-cordova-plugin`\n  * For Intel XDK: Add `pushwoosh-intel-xdk-plugin` as Third-Party Plugin\n\n**2.** Whitelist **.pushwoosh.com** domain in the **config.xml** file:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<access origin=\\\"*.pushwoosh.com\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"Do not forget to add **cordova-plugin-whitelist** plugin for **android** platform.\\n`cordova plugin add cordova-plugin-whitelist`\"\n}\n[/block]\n**3.** Initialize plugin\n\nAdd the following function to your javascript file, enter the correct Pushwoosh App ID.\nFor **Android** also enter the correct Google Project Number. **serviceName** is optional for **Windows Phone** (wp8) \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"function initPushwoosh() {\\n\\tvar pushwoosh = cordova.require(\\\"pushwoosh-cordova-plugin.PushNotification\\\");\\n\\n  // Should be called before pushwoosh.onDeviceReady\\n  document.addEventListener('push-notification', function(event) {\\n\\t\\tvar notification = event.notification;\\n\\t\\t// handle push open here\\n\\t});\\n  \\n\\t// Initialize Pushwoosh. This will trigger all pending push notifications on start.\\n\\tpushwoosh.onDeviceReady({\\n    appid: \\\"PUSHWOOSH_APP_ID\\\",\\n\\t\\tprojectid: \\\"GOOGLE_PROJECT_NUMBER\\\",\\n\\t\\tserviceName: \\\"MPNS_SERVICE_NAME\\\"\\n\\t});\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nCall `initPushwoosh();` on application start.\n\nExample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bindEvents: function() {\\n\\tdocument.addEventListener('deviceready', this.onDeviceReady, false);\\n},\\n// deviceready Event Handler\\n//\\n// The scope of 'this' is the event. In order to call the 'receivedEvent' function, we must explicitly call 'app.receivedEvent(...);'\\nonDeviceReady: function() {\\n\\tapp.receivedEvent('deviceready');\\n\\tinitPushwoosh();\\n},\",\n      \"language\": \"javascript\",\n      \"name\": \"Cordova/PhoneGap\"\n    },\n    {\n      \"code\": \"angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])\\n.run(function($ionicPlatform) {\\n  $ionicPlatform.ready(function() {\\n    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard\\n    // for form inputs)\\n    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {\\n      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);\\n      cordova.plugins.Keyboard.disableScroll(true);\\n\\n    }\\n    if (window.StatusBar) {\\n      // org.apache.cordova.statusbar required\\n      StatusBar.styleLightContent();\\n    }\\n\\n    initPushwoosh();\\n  });\\n})\",\n      \"language\": \"javascript\",\n      \"name\": \"Ionic\"\n    },\n    {\n      \"code\": \"function onAppReady() {\\n    if( navigator.splashscreen && navigator.splashscreen.hide ) {   // Cordova API detected\\n        navigator.splashscreen.hide() ;\\n    }\\n\\n    initPushwoosh();\\n}\\ndocument.addEventListener(\\\"app.Ready\\\", onAppReady, false) ;\",\n      \"language\": \"javascript\",\n      \"name\": \"Intel XDK\"\n    }\n  ]\n}\n[/block]\n**4.** Registering and handling push notifications \n\nTo register for push notifications call\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"pushwoosh.registerDevice(\\n\\tfunction(status) {\\n\\t\\tvar pushToken = status.pushToken;\\n    \\t// 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\\tvar notification = event.notification;\\n\\t// handle push open here\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**5.** iOS platform\nIf you use `cordova-ios` earlier than `4.3.0`, enable **Push Notifications** in **Capabilities** section in XCode project.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/546f90c-Screen_Shot_2016-09-20_at_14.39.50.png\",\n        \"Screen Shot 2016-09-20 at 14.39.50.png\",\n        751,\n        181,\n        \"#d8d7d2\"\n      ]\n    }\n  ]\n}\n[/block]\n**6.** Android platform\n\nCheck out the latest **Google Play services** and **Android Support** libraries using **Android SDK Manager**.\n\n**7.** Windows platform\n\nPushwoosh plugin for windows platform uses WNS. **Associate App with the Store** in Visual Studio and set **Notifications->Toast Capable**;\nPlease note that all UWP apps (Windows 10 and higher) are by default capable of sending toast notifications, without the need to declare such capability.\n\nPretty easy, isn't it!","excerpt":"How to integrate Pushwoosh SDK into your Cordova project","slug":"cordova-phonegap","type":"basic","title":"Cordova / PhoneGap"}

Cordova / PhoneGap

How to integrate Pushwoosh SDK into your Cordova project

[block:callout] { "type": "success", "title": "Supports iOS, Android, Windows Phone, Windows" } [/block] [**Download SDK**](https://github.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin) [**Download Sample**](https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample) [**Plugin API Docs**](http://docs.pushwoosh.com/docs/cordova-api-reference) [block:callout] { "type": "info", "body": "iOS Simulator can neither subscribe nor receive push notifications. Android and Windows Phone emulator will work.", "title": "Note:" } [/block] To integrate Pushwoosh with your Cordova application, follow these simple steps: **1.** Install the Plugin source code into your app: * For Phonegap: `phonegap plugin add pushwoosh-cordova-plugin` * For Cordova: `cordova plugin add pushwoosh-cordova-plugin` * For Ionic: `ionic plugin add pushwoosh-cordova-plugin` * For Intel XDK: Add `pushwoosh-intel-xdk-plugin` as Third-Party Plugin **2.** Whitelist **.pushwoosh.com** domain in the **config.xml** file: [block:code] { "codes": [ { "code": "<access origin=\"*.pushwoosh.com\" />", "language": "xml" } ] } [/block] [block:callout] { "type": "warning", "body": "Do not forget to add **cordova-plugin-whitelist** plugin for **android** platform.\n`cordova plugin add cordova-plugin-whitelist`" } [/block] **3.** Initialize plugin Add the following function to your javascript file, enter the correct Pushwoosh App ID. For **Android** also enter the correct Google Project Number. **serviceName** is optional for **Windows Phone** (wp8) [block:code] { "codes": [ { "code": "function initPushwoosh() {\n\tvar pushwoosh = cordova.require(\"pushwoosh-cordova-plugin.PushNotification\");\n\n // Should be called before pushwoosh.onDeviceReady\n document.addEventListener('push-notification', function(event) {\n\t\tvar notification = event.notification;\n\t\t// handle push open here\n\t});\n \n\t// Initialize Pushwoosh. This will trigger all pending push notifications on start.\n\tpushwoosh.onDeviceReady({\n appid: \"PUSHWOOSH_APP_ID\",\n\t\tprojectid: \"GOOGLE_PROJECT_NUMBER\",\n\t\tserviceName: \"MPNS_SERVICE_NAME\"\n\t});\n}", "language": "javascript" } ] } [/block] Call `initPushwoosh();` on application start. Example: [block:code] { "codes": [ { "code": "bindEvents: function() {\n\tdocument.addEventListener('deviceready', this.onDeviceReady, false);\n},\n// deviceready Event Handler\n//\n// The scope of 'this' is the event. In order to call the 'receivedEvent' function, we must explicitly call 'app.receivedEvent(...);'\nonDeviceReady: function() {\n\tapp.receivedEvent('deviceready');\n\tinitPushwoosh();\n},", "language": "javascript", "name": "Cordova/PhoneGap" }, { "code": "angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])\n.run(function($ionicPlatform) {\n $ionicPlatform.ready(function() {\n // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard\n // for form inputs)\n if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {\n cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);\n cordova.plugins.Keyboard.disableScroll(true);\n\n }\n if (window.StatusBar) {\n // org.apache.cordova.statusbar required\n StatusBar.styleLightContent();\n }\n\n initPushwoosh();\n });\n})", "language": "javascript", "name": "Ionic" }, { "code": "function onAppReady() {\n if( navigator.splashscreen && navigator.splashscreen.hide ) { // Cordova API detected\n navigator.splashscreen.hide() ;\n }\n\n initPushwoosh();\n}\ndocument.addEventListener(\"app.Ready\", onAppReady, false) ;", "language": "javascript", "name": "Intel XDK" } ] } [/block] **4.** Registering and handling push notifications To register for push notifications call [block:code] { "codes": [ { "code": "pushwoosh.registerDevice(\n\tfunction(status) {\n\t\tvar pushToken = status.pushToken;\n \t// 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\tvar notification = event.notification;\n\t// handle push open here\n});", "language": "javascript" } ] } [/block] **5.** iOS platform If you use `cordova-ios` earlier than `4.3.0`, enable **Push Notifications** in **Capabilities** section in XCode project. [block:image] { "images": [ { "image": [ "https://files.readme.io/546f90c-Screen_Shot_2016-09-20_at_14.39.50.png", "Screen Shot 2016-09-20 at 14.39.50.png", 751, 181, "#d8d7d2" ] } ] } [/block] **6.** Android platform Check out the latest **Google Play services** and **Android Support** libraries using **Android SDK Manager**. **7.** Windows platform Pushwoosh plugin for windows platform uses WNS. **Associate App with the Store** in Visual Studio and set **Notifications->Toast Capable**; Please note that all UWP apps (Windows 10 and higher) are by default capable of sending toast notifications, without the need to declare such capability. Pretty easy, isn't it!