push.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. function onDeviceReadyPush() {
  2. var push = PushNotification.init({
  3. // forceReload: true,
  4. // forceStart: true,
  5. android: {
  6. senderID: "667898382143"
  7. },
  8. browser: {
  9. pushServiceURL: 'http://push.api.phonegap.com/v1/push'
  10. },
  11. ios: {
  12. alert: "true",
  13. badge: "true",
  14. sound: "true"
  15. },
  16. windows: {}
  17. });
  18. /*
  19. * registra l'id univoco dell'installazione su xm.bus.pm
  20. */
  21. push.on('registration', function(registration) {
  22. console.log(JSON.stringify(registration));
  23. var url = "https://xm.bus.pm/api/d/c?device=" + registration.registrationId;
  24. $.get(url, function( data ) {
  25. console.log(JSON.stringify(data));
  26. });
  27. });
  28. /*
  29. * gestisce la notifica ricevuta
  30. */
  31. push.on('notification', function(data) {
  32. console.log(JSON.stringify(data));
  33. // alert(JSON.stringify(data));
  34. $("body").pagecontainer("change", "#alert");
  35. $("#alert-title").html(data.title);
  36. $("#alert-message").html(data.message);
  37. });
  38. push.on('error', function(e) {
  39. console.log(JSON.stringify(e));
  40. });
  41. };
  42. document.addEventListener('deviceready', onDeviceReadyPush, true);