Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. var app = {
  2. initialize: function() {
  3. this.bindEvents();
  4. },
  5.  
  6. bindEvents: function() {
  7. document.addEventListener('deviceready', this.onDeviceReady, false);
  8. },
  9.  
  10. onDeviceReady: function() {
  11. app.receivedEvent('deviceready');
  12. },
  13. receivedEvent: function(id) {
  14. var parentElement = document.getElementById(id);
  15. var listeningElement = parentElement.querySelector('.listening');
  16. var receivedElement = parentElement.querySelector('.received');
  17.  
  18. listeningElement.setAttribute('style', 'display:none;');
  19. receivedElement.setAttribute('style', 'display:block;');
  20.  
  21. console.log('Received Event: ' + id);
  22. var pushNotification = window.plugins.pushNotification;
  23. alert("Register called");
  24. pushNotification.register(this.successHandler, this.errorHandler,{"senderID":"543180841340","ecb":"app.onNotificationGCM"});
  25. },
  26. successHandler: function(result) {
  27. alert('Callback Success! Result = '+result)
  28. },
  29. errorHandler:function(error) {
  30. alert(error);
  31. },
  32. onNotificationGCM: function(e) {
  33. switch( e.event )
  34. {
  35. case 'registered':
  36. if ( e.regid.length > 0 )
  37. {
  38. console.log("Regid " + e.regid);
  39. alert('registration id = '+e.regid);
  40. document.getElementById('regId').value = e.regid;
  41. }
  42. break;
  43.  
  44. case 'message':
  45. alert('message = '+e.message+' msgcnt = '+e.msgcnt);
  46. break;
  47.  
  48. case 'error':
  49. alert('GCM error = '+e.msg);
  50. break;
  51.  
  52. default:
  53. alert('An unknown GCM event has occurred');
  54. break;
  55. }
  56. },
  57. onNotificationAPN: function(event) {
  58. var pushNotification = window.plugins.pushNotification;
  59. alert("Running in JS - onNotificationAPN - Received a notification! " + event.alert);
  60.  
  61. if (event.alert) {
  62. navigator.notification.alert(event.alert);
  63. }
  64. if (event.badge) {
  65. pushNotification.setApplicationIconBadgeNumber(this.successHandler, this.errorHandler, event.badge);
  66. }
  67. if (event.sound) {
  68. var snd = new Media(event.sound);
  69. snd.play();
  70. }
  71. }
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement