Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. var xxx = angular.module('starter', ['ionic', 'ngCordova'])
  2.  
  3. xxx.run(function ($ionicPlatform, $cordovaPush) {
  4.  
  5. $ionicPlatform.ready(function () {
  6.  
  7. if (window.cordova && window.cordova.plugins.Keyboard) {
  8. cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  9. }
  10.  
  11. if (window.StatusBar) {
  12. StatusBar.styleDefault();
  13. }
  14.  
  15. var androidConfig = {
  16.  
  17. "senderID": "5757xxxxxxx",
  18. };
  19.  
  20. document.addEventListener("deviceready", function () {
  21. $cordovaPush.register(androidConfig).then(function (result) {
  22. alert(result);
  23. }, function (err) {
  24. alert(err);
  25. })
  26.  
  27.  
  28. $rootScope.$on('$cordovaPush:notificationReceived', function (event, notification) {
  29. switch (notification.event) {
  30. case 'registered':
  31. if (notification.regid.length > 0) {
  32. alert('registration ID = ' + notification.regid);
  33. }
  34. break;
  35.  
  36. case 'message':
  37. // this is the actual push notification. its format depends on the data model from the push server
  38. alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
  39. break;
  40.  
  41. case 'error':
  42. alert('GCM error = ' + notification.msg);
  43. break;
  44.  
  45. default:
  46. alert('An unknown GCM event has occurred');
  47. break;
  48. }
  49. });
  50.  
  51.  
  52. // WARNING: dangerous to unregister (results in loss of tokenID)
  53. $cordovaPush.unregister(options).then(function (result) {
  54. // Success!
  55. }, function (err) {
  56. // Error
  57. })
  58.  
  59. }, false)
  60.  
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement