fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
623 stars 997 forks source link

Cannot Get push notification #65

Open sharifnascenia opened 8 years ago

sharifnascenia commented 8 years ago

I am using the code described in the 'using' portion. I can get the register token. Then I tried to send notification from Firebase test notification module using that token. Each time I run the app in my device I am having the alert-

"Msg: onNotification callback successfully registered: OK"

it is inside the second function of FCMPlugin.onNotification event.

But the first function [where I want to get the notification] is not called. I don't find where I am making mistake. Here is my code inside onDeviceReady:

document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );

// TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
var parentElement = document.getElementById('deviceready');
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');

//=========================
FCMPlugin.getToken(
  function (token) {
      alert("Token: " + token);
          cordova.plugins.email.open({
              to: 'sharif@nascenia.com',
              subject: 'Greetings',
              body: token
          });
  },
  function (err) {
      alert("Error: " + 'error retrieving token: ' + err);
  }
);

FCMPlugin.onNotification(
  function (data) {
      alert("Notify: " + JSON.stringify(data));
      if (data.wasTapped) {
          //Notification was received on device tray and tapped by the user. 
          alert("Wrapped Notify: " + JSON.stringify(data));
      } else {
          //Notification was received in foreground. Maybe the user needs to be notified. 
          alert("Notify: " + JSON.stringify(data));
      }
  },
  function (msg) {
      alert("Msg: " + 'onNotification callback successfully registered: ' + msg.Notification);
  },
  function (err) {
      alert("Error: " + 'Error registering onNotification callback: ' + err);
  }
);
pfeldman commented 8 years ago

Have you solved it? I'm having the same issue

sharifnascenia commented 8 years ago

Yes, I did. It was problem with my redimi note 2. Otherwise It works on other android devices

On Sun, Oct 2, 2016 at 12:07 PM, Pablo Feldman notifications@github.com wrote:

Have you solved it? I'm having the same issue

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fechanique/cordova-plugin-fcm/issues/65#issuecomment-250955780, or mute the thread https://github.com/notifications/unsubscribe-auth/ANZq35r8VeyTRcpli6plWE7EKQlyoiRZks5qv0oagaJpZM4Jev5- .