fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
624 stars 990 forks source link

onNotification not called when app not active #526

Closed fortunella closed 5 years ago

fortunella commented 5 years ago

I have a similar problem as described in #525. But in my case, I get the notifications when the app is in background, as I would expect.

But when I tap on the notification the onNotification handler is not called. When the app is active, the onNotification handler is called.

This is the call in my app.component.ts:

FCMPlugin.onNotification(
  (data) => {
    console.log(data);
    if (data.wasTapped) {
      //Notification was received on device tray and tapped by the user.
      ...
    } else {
      //Notification was received in foreground. Maybe the user needs to be notified.
      ...
    }
  },
  (msg) => {
    console.log('onNotification callback successfully registered: ' + msg);
  },
  (err) => {
    console.log('Error registering onNotification callback: ' + err);
  }
);

cordova --version : 7.1.0 cordova platform version android: 6.4.0

salime45 commented 5 years ago

Hi

How you send the notification?

What is the payload of notification?

fortunella commented 5 years ago

The notification is sent from a Java Spring Boot application. It is sent to a specific topic and the payload only a UUID.

My app has a list of items. When you tap an item you jump into a details view. The UUID in the payload is the one of a certain item in the list. When the user taps on the notification the details view of the corresponding item should be opened.

I think it's the same problem as in #528

orehush commented 5 years ago

Hello @fortunella you should add this param "click_action":"FCM_PLUGIN_ACTIVITY" to notification payload. See here

fortunella commented 5 years ago

Thanks a lot. Works fine. I missed that when reading through the docs.

ragcsalo commented 2 years ago

This only works on Android, not on iOS... :-/