{"_id":"5829056d4ca29e0f00137aed","user":"56cecbb2e50c9c1b008303eb","version":{"_id":"56cecbdc44c5700b0095c03d","project":"56cecbdb44c5700b0095c03a","__v":10,"createdAt":"2016-02-25T09:39:40.121Z","releaseDate":"2016-02-25T09:39:40.121Z","categories":["56cecbdc44c5700b0095c03e","56d1d2c05ad7ad0b00b7e809","56d1d2fa5ad7ad0b00b7e80a","56d369331660770b00081159","56d3693d1660770b0008115a","56e5361e7990160e002e3fbc","56e5362775eb791700a9c4d2","57a9030947f2f419009188d4","57b4705ee9e4c60e00f6f4c3","5828f5b04774ab0f005179a2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"parentDoc":null,"category":{"_id":"5828f5b04774ab0f005179a2","project":"56cecbdb44c5700b0095c03a","version":"56cecbdc44c5700b0095c03d","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-11-13T23:22:24.866Z","from_sync":false,"order":3,"slug":"phonegap-cordova","title":"Phonegap / Cordova"},"githubsync":"","__v":0,"project":"56cecbdb44c5700b0095c03a","metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-11-14T00:29:33.665Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Initialization\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.onDeviceReady(sdkKey, appGroup)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nShould be call on each app load, with your PushApps SDK key (string).\n**Parameters:**\nsdkKey - string, your PushApps SDK key\nappGroup - string, iOS ONLY\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Push Notifications Registration\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.registerToPushNotifications(function (pushToken) { ... }, function (errorMsg) { ... })\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nCall this method to register the current device for receiving push notifications. Please notice that if you call this method, after disabling push notifications via **PushNotification.enablePush(false)**, than nothing will happen (we won't enable notifications again).\n**Parameters:**\nsuccess callback - giving you back the push token for this device.\nerror callback - giving you an informative message on what went wrong.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.enablePush(enablePush)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThis method enables you to allow the user to decide if he want to enable or disable push notifications, according to the boolean parameter (enablePush).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.isPushEnabled(function (enabled) { ... })\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nReturns true if push notifications are enabled for this device. Otherwise, returns false.\n**Parameters:**\ncallback - giving you back the current device status for push notifications.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.enableSound(enableSound)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**Android ONLY**\nThis method enables you to allow the user to decide if he want to enable or disable sound for push notifications, according to the boolean parameter (enableSound).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.isSoundEnabled(function (enabled) { ... })\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**Android ONLY**\nReturns true if sound is enabled for push notifications. Otherwise, returns false.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.enableVibrate(enableVibrate)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**Android ONLY**\nThis method enables you to allow the user to decide if he want to enable or disable vibration for push notifications, according to the boolean parameter (enableSound).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.isVibrateEnabled(function (enabled) { ... })\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**Android ONLY**\nReturns true if vibration is enabled for push notifications. Otherwise, returns false.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Handle Push Notifications Clicks\"\n}\n[/block]\nTo handle the click on the push notifications (e.g. if you want to take the user to a specific page, according to the notification he clicked on), you need to register to a HTML event, on app load (we advise on doing it only after device ready event as been called):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"document.addEventListener('pushapps.message-clicked', onPushMessageClicked, false);\\nfunction onPushMessageClicked(event) {\\n    var notification = event.notification;\\n    alert(notification[\\\"n_id\\\"]); // This will show the notification id, givven by the PushApps system\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIf your using PushApps **content recommendations** feature, you can extract the clicked article and to check if its a video, by executing the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"function onPushMessageClicked(event) {\\n    var notification = event.notification;\\n    var articleUrl = notification[\\\"PAArticleUrl\\\"];\\n  \\tvar isVideo = notification[\\\"PANotificationClickType\\\"] === \\\"Video\\\";\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Tracking Reading History\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.trackUrlView(\\\"http://...\\\")\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nTo improve PushApps content recommendations, please update our SDK with each article url has read. Please notice it should be a full HTTP url.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"User & SDK Data\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.getDeviceId(function (deviceId) { ... })\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nGet the device id, as represented in the PushApps system.\n**Parameters:**\ncallback - giving you back the current device id.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.getSdkVersion(function (sdkVersion) { ... })\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nGet the current PushApps SDK version (please notice it will return different version for iOS and Android).\n**Parameters:**\ncallback - giving you back the current SDK version.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Tags\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.addTag(name, value)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nAdds the device to a specific group. For example \"Females\".\n**Parameters:**\nname - string, should **not** include whitespace.\nvalue - boolean, indicates if the current device belongs to that group (e.g true if its a female, false if its man, do not add the tag if unknown).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.removeTag(name)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nRemove the device from that group.\n**Parameters:**\nname - string, the name of the tag.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushNotification.getTags(function (tags) { ... } )\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nGet the tags associated with the current device.\n**Parameters:**\nA callback with the tags array as an input. Each tag will be in the following form:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"name\\\" : \\\"female\\\",\\n  \\\"value\\\" : true\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"api-reference","type":"basic","title":"API Reference"}
[block:api-header] { "type": "basic", "title": "Initialization" } [/block] [block:code] { "codes": [ { "code": "PushNotification.onDeviceReady(sdkKey, appGroup)", "language": "javascript" } ] } [/block] Should be call on each app load, with your PushApps SDK key (string). **Parameters:** sdkKey - string, your PushApps SDK key appGroup - string, iOS ONLY [block:api-header] { "type": "basic", "title": "Push Notifications Registration" } [/block] [block:code] { "codes": [ { "code": "PushNotification.registerToPushNotifications(function (pushToken) { ... }, function (errorMsg) { ... })", "language": "javascript" } ] } [/block] Call this method to register the current device for receiving push notifications. Please notice that if you call this method, after disabling push notifications via **PushNotification.enablePush(false)**, than nothing will happen (we won't enable notifications again). **Parameters:** success callback - giving you back the push token for this device. error callback - giving you an informative message on what went wrong. [block:code] { "codes": [ { "code": "PushNotification.enablePush(enablePush)", "language": "javascript" } ] } [/block] This method enables you to allow the user to decide if he want to enable or disable push notifications, according to the boolean parameter (enablePush). [block:code] { "codes": [ { "code": "PushNotification.isPushEnabled(function (enabled) { ... })", "language": "javascript" } ] } [/block] Returns true if push notifications are enabled for this device. Otherwise, returns false. **Parameters:** callback - giving you back the current device status for push notifications. [block:code] { "codes": [ { "code": "PushNotification.enableSound(enableSound)", "language": "javascript" } ] } [/block] **Android ONLY** This method enables you to allow the user to decide if he want to enable or disable sound for push notifications, according to the boolean parameter (enableSound). [block:code] { "codes": [ { "code": "PushNotification.isSoundEnabled(function (enabled) { ... })", "language": "javascript" } ] } [/block] **Android ONLY** Returns true if sound is enabled for push notifications. Otherwise, returns false. [block:code] { "codes": [ { "code": "PushNotification.enableVibrate(enableVibrate)", "language": "javascript" } ] } [/block] **Android ONLY** This method enables you to allow the user to decide if he want to enable or disable vibration for push notifications, according to the boolean parameter (enableSound). [block:code] { "codes": [ { "code": "PushNotification.isVibrateEnabled(function (enabled) { ... })", "language": "javascript" } ] } [/block] **Android ONLY** Returns true if vibration is enabled for push notifications. Otherwise, returns false. [block:api-header] { "type": "basic", "title": "Handle Push Notifications Clicks" } [/block] To handle the click on the push notifications (e.g. if you want to take the user to a specific page, according to the notification he clicked on), you need to register to a HTML event, on app load (we advise on doing it only after device ready event as been called): [block:code] { "codes": [ { "code": "document.addEventListener('pushapps.message-clicked', onPushMessageClicked, false);\nfunction onPushMessageClicked(event) {\n var notification = event.notification;\n alert(notification[\"n_id\"]); // This will show the notification id, givven by the PushApps system\n}", "language": "javascript" } ] } [/block] If your using PushApps **content recommendations** feature, you can extract the clicked article and to check if its a video, by executing the following code: [block:code] { "codes": [ { "code": "function onPushMessageClicked(event) {\n var notification = event.notification;\n var articleUrl = notification[\"PAArticleUrl\"];\n \tvar isVideo = notification[\"PANotificationClickType\"] === \"Video\";\n}", "language": "javascript" } ] } [/block] [block:api-header] { "type": "basic", "title": "Tracking Reading History" } [/block] [block:code] { "codes": [ { "code": "PushNotification.trackUrlView(\"http://...\")", "language": "javascript" } ] } [/block] To improve PushApps content recommendations, please update our SDK with each article url has read. Please notice it should be a full HTTP url. [block:api-header] { "type": "basic", "title": "User & SDK Data" } [/block] [block:code] { "codes": [ { "code": "PushNotification.getDeviceId(function (deviceId) { ... })", "language": "javascript" } ] } [/block] Get the device id, as represented in the PushApps system. **Parameters:** callback - giving you back the current device id. [block:code] { "codes": [ { "code": "PushNotification.getSdkVersion(function (sdkVersion) { ... })", "language": "javascript" } ] } [/block] Get the current PushApps SDK version (please notice it will return different version for iOS and Android). **Parameters:** callback - giving you back the current SDK version. [block:api-header] { "type": "basic", "title": "Tags" } [/block] [block:code] { "codes": [ { "code": "PushNotification.addTag(name, value)", "language": "javascript" } ] } [/block] Adds the device to a specific group. For example "Females". **Parameters:** name - string, should **not** include whitespace. value - boolean, indicates if the current device belongs to that group (e.g true if its a female, false if its man, do not add the tag if unknown). [block:code] { "codes": [ { "code": "PushNotification.removeTag(name)", "language": "javascript" } ] } [/block] Remove the device from that group. **Parameters:** name - string, the name of the tag. [block:code] { "codes": [ { "code": "PushNotification.getTags(function (tags) { ... } )", "language": "javascript" } ] } [/block] Get the tags associated with the current device. **Parameters:** A callback with the tags array as an input. Each tag will be in the following form: [block:code] { "codes": [ { "code": "{\n \"name\" : \"female\",\n \"value\" : true\n}", "language": "json" } ] } [/block]