{"__v":1,"_id":"579716002cd23b0e00283c79","category":{"__v":0,"_id":"55b9ffa5d72d1e1900276a39","pages":[],"project":"5540ce1b31827a0d007ab1cc","version":"5540ce1c31827a0d007ab1cf","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,"project":"5540ce1b31827a0d007ab1cc","user":"55b8b82fdec1c9210013cfa1","version":{"__v":31,"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","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":[],"next":{"pages":[],"description":""},"createdAt":"2016-07-26T07:49:20.816Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Push Notifications in Foreground\"\n}\n[/block]\nBy default Pushwoosh plugin does not display notifications in the foreground and automatically triggers `push-notification` event. This can be controlled by using **IOS_FOREGROUND_ALERT_TYPE** and **ANDROID_FOREGROUND_PUSH** preferences:\n\n**IOS_FOREGROUND_ALERT_TYPE** \n* `BANNER` – displays banner in-app alert\n* `ALERT` – alert notification\n* `NONE` – do not display a notification when the app is in the foreground (default)\n\n**ANDROID_FOREGROUND_PUSH**\n* `true` – do not automatically handle foreground pushes\n* `false` – automatically handle foreground pushes (default)\n\nExample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"cordova plugin add pushwoosh-cordova-plugin --variable IOS_FOREGROUND_ALERT_TYPE=\\\"ALERT\\\" --variable ANDROID_FOREGROUND_PUSH=\\\"true\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Custom Push Sound\"\n}\n[/block]\nTo enable custom push notifications sounds for Android place sound samples in **www/res** folder. The sounds will be accessible in **Sound** dropdown menu of **Send Push** panel.\nIn iOS, sound files are not automatically associated with Pushwoosh Application yet, but can be used manually, e.g. `www/res/sound_name.wav`.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"iOS\",\n  \"body\": \"iOS notifications support only .aiff, .wav and .caf file formats\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Custom Push Icon\"\n}\n[/block]\nPush notification icon can be customized on Android locally by using `pw_notification` as resource name for such icon (see sample [1](https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample/blob/master/Cordova/hooks/after_platform_add/2_set_notification_icon.js) [2](https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample/tree/master/Cordova/config/android/res)); or remotely by referencing any resource name in **Icon** setting in **Send Push** panel.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Custom Push Data\"\n}\n[/block]\nCustom push data can be sent using **Action** setting in the **Send Push** panel. To receive and handle such data use the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"document.addEventListener('push-notification',\\n  function(event) {\\n    var message = event.notification.message; // Push message\\n    var userData = event.notification.userdata; // Custom push data\\n\\n    if (userData) {\\n      // handle custom push data here\\n    }\\n  }\\n);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Controlling Log Level\"\n}\n[/block]\nIn order to assist with debugging and integration, SDK will print all the requests to the console by default. When you are ready for the production build, set `LOG_LEVEL` variable to one of the following values:\n\n* `NONE` – no logs from the SDK\n* `ERROR` – only display errors in the console\n* `WARNING` – show warnings\n* `INFO` – show informational messages\n* `DEBUG` – show everything, including debug information (default)\n\nExample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"cordova plugin add pushwoosh-cordova-plugin --variable LOG_LEVEL=\\\"INFO\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Geozones Push Notifications\"\n}\n[/block]\n**1.** To enable location tracking in your application:\n\n**1.1** For **iOS** follow this [guide](http://docs.pushwoosh.com/docs/customizing-ios-sdk#geozones-push-notifications)\n\n**1.2** For **Android** add the following permissions:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"android.permission.ACCESS_COARSE_LOCATION\\\" />\\n<uses-permission android:name=\\\"android.permission.ACCESS_FINE_LOCATION\\\" />\",\n      \"language\": \"xml\",\n      \"name\": \"AndroidManifest.xml\"\n    }\n  ]\n}\n[/block]\n**1.3** For **Windows Phone** add the following capabilities:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<Capabilities>\\n      ...\\n      <Capability Name=\\\"ID_CAP_LOCATION\\\" />\\n</Capabilities>\",\n      \"language\": \"xml\",\n      \"name\": \"WMAppManifiest.xml\"\n    }\n  ]\n}\n[/block]\n**2.** To start location tracking simply call:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var pushwoosh = cordova.require(\\\"pushwoosh-cordova-plugin.PushNotification\\\");\\npushwoosh.startLocationTracking();\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Deep linking\"\n}\n[/block]\nWe recommend using https://github.com/nordnet/cordova-universal-links-plugin\nIt's super easy to set deep links for Cordova and it works with Pushwoosh deep linking functionality out of the box.\n\nFor example add the following to Cordova **config.xml**:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<universal-links>\\n    <host name=\\\"sample.com\\\" scheme=\\\"pushwoosh\\\" event=\\\"ul_myExampleEvent\\\" />\\n</universal-links>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nThis will set the deep link for *pushwoosh://sample.com* and will trigger `ul_myExampleEvent`\n\nAlso, add the following to your javascript code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"universalLinks.subscribe('ul_myExampleEvent', function (eventData) {\\n    // handle deep link open here\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"customizing-cordova-plugin","type":"basic","title":"Customizing Plugin"}

Customizing Plugin


[block:api-header] { "type": "basic", "title": "Push Notifications in Foreground" } [/block] By default Pushwoosh plugin does not display notifications in the foreground and automatically triggers `push-notification` event. This can be controlled by using **IOS_FOREGROUND_ALERT_TYPE** and **ANDROID_FOREGROUND_PUSH** preferences: **IOS_FOREGROUND_ALERT_TYPE** * `BANNER` – displays banner in-app alert * `ALERT` – alert notification * `NONE` – do not display a notification when the app is in the foreground (default) **ANDROID_FOREGROUND_PUSH** * `true` – do not automatically handle foreground pushes * `false` – automatically handle foreground pushes (default) Example: [block:code] { "codes": [ { "code": "cordova plugin add pushwoosh-cordova-plugin --variable IOS_FOREGROUND_ALERT_TYPE=\"ALERT\" --variable ANDROID_FOREGROUND_PUSH=\"true\"", "language": "shell" } ] } [/block] [block:api-header] { "type": "basic", "title": "Custom Push Sound" } [/block] To enable custom push notifications sounds for Android place sound samples in **www/res** folder. The sounds will be accessible in **Sound** dropdown menu of **Send Push** panel. In iOS, sound files are not automatically associated with Pushwoosh Application yet, but can be used manually, e.g. `www/res/sound_name.wav`. [block:callout] { "type": "warning", "title": "iOS", "body": "iOS notifications support only .aiff, .wav and .caf file formats" } [/block] [block:api-header] { "type": "basic", "title": "Custom Push Icon" } [/block] Push notification icon can be customized on Android locally by using `pw_notification` as resource name for such icon (see sample [1](https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample/blob/master/Cordova/hooks/after_platform_add/2_set_notification_icon.js) [2](https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample/tree/master/Cordova/config/android/res)); or remotely by referencing any resource name in **Icon** setting in **Send Push** panel. [block:api-header] { "type": "basic", "title": "Custom Push Data" } [/block] Custom push data can be sent using **Action** setting in the **Send Push** panel. To receive and handle such data use the following code: [block:code] { "codes": [ { "code": "document.addEventListener('push-notification',\n function(event) {\n var message = event.notification.message; // Push message\n var userData = event.notification.userdata; // Custom push data\n\n if (userData) {\n // handle custom push data here\n }\n }\n);", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Controlling Log Level" } [/block] In order to assist with debugging and integration, SDK will print all the requests to the console by default. When you are ready for the production build, set `LOG_LEVEL` variable to one of the following values: * `NONE` – no logs from the SDK * `ERROR` – only display errors in the console * `WARNING` – show warnings * `INFO` – show informational messages * `DEBUG` – show everything, including debug information (default) Example: [block:code] { "codes": [ { "code": "cordova plugin add pushwoosh-cordova-plugin --variable LOG_LEVEL=\"INFO\"", "language": "shell" } ] } [/block] [block:api-header] { "type": "basic", "title": "Geozones Push Notifications" } [/block] **1.** To enable location tracking in your application: **1.1** For **iOS** follow this [guide](http://docs.pushwoosh.com/docs/customizing-ios-sdk#geozones-push-notifications) **1.2** For **Android** add the following permissions: [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" />\n<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" />", "language": "xml", "name": "AndroidManifest.xml" } ] } [/block] **1.3** For **Windows Phone** add the following capabilities: [block:code] { "codes": [ { "code": "<Capabilities>\n ...\n <Capability Name=\"ID_CAP_LOCATION\" />\n</Capabilities>", "language": "xml", "name": "WMAppManifiest.xml" } ] } [/block] **2.** To start location tracking simply call: [block:code] { "codes": [ { "code": "var pushwoosh = cordova.require(\"pushwoosh-cordova-plugin.PushNotification\");\npushwoosh.startLocationTracking();", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Deep linking" } [/block] We recommend using https://github.com/nordnet/cordova-universal-links-plugin It's super easy to set deep links for Cordova and it works with Pushwoosh deep linking functionality out of the box. For example add the following to Cordova **config.xml**: [block:code] { "codes": [ { "code": "<universal-links>\n <host name=\"sample.com\" scheme=\"pushwoosh\" event=\"ul_myExampleEvent\" />\n</universal-links>", "language": "xml" } ] } [/block] This will set the deep link for *pushwoosh://sample.com* and will trigger `ul_myExampleEvent` Also, add the following to your javascript code: [block:code] { "codes": [ { "code": "universalLinks.subscribe('ul_myExampleEvent', function (eventData) {\n // handle deep link open here\n});", "language": "javascript" } ] } [/block]