1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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(notification) {
- console.log(JSON.stringify(notification));
- switch(notification.additionalData.type) {
- case 'event':
- /*
- * Questo è il reminder o la pubblicazione di un evento
- */
- var eventId = notification.additionalData.data.id;
- var eventUrl = notification.additionalData.url;
- /*
- * TODO: mandare l'utente all'evento..
- * l'url servirebbe solo se lo si vuole fare in webview
- * altrimenti bisognerebbe fare il fetch dell'xml dal sito,
- * salvarlo o comunque visualizzare la pagina
- */
- break;
- case 'post':
- /*
- * Questo è il reminder o la pubblicazione di un post
- */
- var postId = notification.additionalData.data.id;
- var postUrl = notification.additionalData.url;
- /*
- * TODO: mandare l'utente al post..
- * l'url servirebbe solo se lo si vuole fare in webview
- * altrimenti bisognerebbe fare il fetch dell'xml o json dal sito,
- * salvarlo o comunque visualizzare la pagina
- */
- break;
- case 'notice':
- /*
- * Questa è una comunicazione generica
- */
- // TODO: cosa mettere nel payload? Che fare?
- break;
- case 'alarm':
- /*
- * Questa è una comunicazione importante
- */
- // TODO: cosa mettere nel payload? Che fare? Qui per esempio mostro semplicemente il messaggio
- $("body").pagecontainer("change", "#alert");
- $("#alert-title").html(notification.title);
- $("#alert-message").html(notification.message);
- break;
- }
- });
- push.on('error', function(e) {
- console.log(JSON.stringify(e));
- });
- }
- document.addEventListener('deviceready', onDeviceReadyPush, true);
|