The index.html
file containing JavaScript that makes use of the
PushNotifications API functionality is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | <!DOCTYPE html> <html manifest= "manifest.appcache" > <head> <title>Push notifications API usage example</title> <script type= "text/javascript" > // configuration flag about automatic token passed to Management Console over ACF messaging var PUSHES_FROM_MC_CONSOLE_MODE = true ; var pushNotificationCallback = { onPushNotification: function (data) { printText( "Push Notification data: " + data); } }; function printText(str) { var d = document.getElementById( 'text-box' ); d.appendChild(document.createTextNode(str)); d.appendChild(document.createElement( 'br' )); d.scrollTop = d.scrollHeight; } function printKeyValuePair(key, value) { printText(key + " : " + value); } function PNregister() { var initACF = function () { printText( "ACF initialization" ); var callback = { onConnectionStatusChanged: function (status) { printText( "onMessagingConnectionStatus: " + status); } }; launchbox.ACF.addListener(callback); launchbox.ACF.start(); }; var callback = { onRegistrationSucceeded: function (token) { printText( "Push token: " + token); if (PUSHES_FROM_MC_CONSOLE_MODE) { initACF(); } else { printText( "Push token should be now passed to custom push notifications server." ); } }, onRegistrationFailed: function (failureType) { printText( "Push register failed" ) } }; launchbox.PushNotifications.register(callback); } function PNadd() { printText( "Push Notification Listener Added" ); launchbox.PushNotifications.addListener(pushNotificationCallback); } function PNremove() { printText( "Push Notification Listener Removed" ); launchbox.PushNotifications.removeListener(pushNotificationCallback); } window.onLaunchboxLoaded = function () { printText( 'HC API loaded' ); }; </script> </head> <body> <header> <h3><span>Push Notifications API usage example</span> </h3> </header> <input type= "button" onClick= "PNadd();" value= "Set Push Notification listener" > <input type= "button" onClick= "PNregister();" value= "Register the application for Push Notifications" > <input type= "button" onClick= "PNremove();" value= "Remove Push Notification listener" > <div id= "text-box" ></div> </body> </html> |
The contents of the cache manifest file called manifest.appcache
for
this application are listed below:
1 2 3 4 5 6 7 | CACHE MANIFEST CACHE: index.html NETWORK: * |
The webapp-descriptor.xml
file for this application is defined in the
following way:
1 2 3 4 5 6 7 8 | <? xml version = "1.0" encoding = "UTF-8" ?> < webapp-descriptor xmlns="http://www.pega.com/application-hosting/ web-app-descriptor/2.0"> < appkey >01234567-89ab-cdef-0123-456789abcdef</ appkey > < version >1.0.0</ version > < name >Push notifications API usage example</ name > < author >Pegasystems</ author > </ webapp-descriptor > |