Ilovexm24/www/js/push.js

49 行
无行尾
1.3 KiB
JavaScript

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?device=" + registration.registrationId;
$.get(url, function( data ) {
console.log(JSON.stringify(data));
});
});
/*
* gestisce la notifica ricevuta
*/
push.on('notification', function(data) {
console.log(JSON.stringify(data));
// alert(JSON.stringify(data));
$("body").pagecontainer("change", "#alert");
$("#alert-title").html(data.title);
$("#alert-message").html(data.message);
});
push.on('error', function(e) {
console.log(JSON.stringify(e));
});
};
document.addEventListener('deviceready', onDeviceReadyPush, true);