123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- function onDeviceReadyPush() {
- var push = PushNotification.init({
- // forceReload: true,
- // forceStart: true,
- android: {
- senderID: "667898382143"
- },
- browser: {
- pushServiceURL: 'http://push.api.phonegap.com/v1/push'
- },
- ios: {
- alert: "true",
- badge: "true",
- sound: "true"
- },
- windows: {}
- });
- /*
- * registra l'id univoco dell'installazione su xm.bus.pm
- */
- push.on('registration', function(registration) {
- console.log(JSON.stringify(registration));
- var url = "https://xm.bus.pm/api/d/c?token=" + registration.registrationId + "&token_type=gcm&topic=xm24";
- $.get(url, function( data ) {
- console.log(JSON.stringify(data));
- });
- });
- /*
- * gestisce la notifica ricevuta
- */
- push.on('notification', function(data) {
- console.log(JSON.stringify(data));
- if(data.additionalData.type === 'alarm')
- {
- /*
- * QUESTA è una COMUNICAZIONE IMPORTANTE!
- */
- $("body").pagecontainer("change", "#alert");
- $("#alert-title").html(data.title);
- $("#alert-message").html(data.message);
- }
- else
- {
- /*
- * QUESTO è un SEMPLICE AGGIORNAMENTO!
- */
- if(!empty(data.additionalData.url))
- {
- console.log('HO UN URL VALIDO '+data.additionalData.url);
- }
- else {
- console.log('NESSUN URL, DEVO VISUALIZZARE DA QUALCHE PARTE MESSAGGIO E TITOLO..');
- }
- }
- });
- push.on('error', function(e) {
- console.log(JSON.stringify(e));
- });
- };
- document.addEventListener('deviceready', onDeviceReadyPush, true);
|