Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle onNotification event in ngCordova push plugin

as a code template doing it like this,

.controller('PushNotificationsCtrl', function ($scope, $cordovaPush) {
var androidConfig = {
"senderID":"372433177444",
"ecb":"onNotification"
};

$cordovaPush.register(androidConfig).then(function(result) {
  // Success!
  $scope.pushSuccess = result
}, function(err) {
  $scope.pushSuccess = err;
});

I manage to successfully get an RegID from GCM. But then how do I manage onNotification from androidConfig ?

like image 577
Azizi Musa Avatar asked Oct 01 '14 04:10

Azizi Musa


People also ask

What is MoEngage push notification?

To deliver push notifications to app customers, marketers launch the campaign using marketing partner tools like MoEngage. The marketer's campaign is then sent to cloud messaging platforms such as FCM, and APNS. These messaging platforms deliver the notification from the marketing partner to the end customer's device.

What are Webpush notifications?

Web push notifications are small message alerts that are displayed on a visitor's desktop, tablet, or mobile device when they have their web browser open.


1 Answers

i found the solution.

instead of doing this :

var androidConfig = {
"senderID":"372433177444",
"ecb":"onNotification"
};

I do like this :

var androidConfig = {
"senderID":"372433177444",
"ecb":"window.onNotification"
};

then

window.onNotification = function(e) {
  switch( e.event )
  {
      case 'registered':
          if ( e.regid.length > 0 )
          {
              console.log("Your regID is : " + e.regid);
          }
          break;

      case 'message':
          // this is the actual push notification. its format depends on the data model     from the push server
          console.log('message = '+e.message);
          angular.element(document.querySelector('#yata')).html(e.message);
          break;

      case 'error':
          console.log('GCM error = '+e.msg);
          break;

      default:
          console.log('An unknown GCM event has occurred');
          break;
  }
};

all work as expected now :)

like image 191
Azizi Musa Avatar answered Sep 29 '22 01:09

Azizi Musa