Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM: Cannot click notification

I'm using the recently release FCM messaging support for push notifications on the chrome. When my app is in the background, I get the notification but nothing happens when I click the notification. How to I specify the URL which should open when the user clicks the notification? (I understand how its done using the pure service worker concept using the notificationclick event, I want to know how to do that using FCM messaging.)

messaging.setBackgroundMessageHandler(function(payload) {
  var data = payload || {};
  var shinyData = decoder.run(data);

  console.log('[firebase-messaging-sw.js] Received background message ', shinyData);

  return self.registration.showNotification(shinyData.title, {
    body: shinyData.body,
    icon: shinyData.icon
  })
});

What am I missing here?

like image 617
Vibgy Avatar asked Oct 23 '16 10:10

Vibgy


People also ask

Is there any limit for FCM?

Maximum message rate to a single device For Android, you can send up to 240 messages/minute and 5,000 messages/hour to a single device.

What is collapse key in FCM?

The collapse key collapses only the notifications bearing the same collapse key. If a user sends 10 notifications with the same collapse key (for example, "SCORE") and 2 notifications without any collapse key and they are not received by the device as the device was offline.


1 Answers

click_action is not one of the possible parameters of the showNotification function.

To handle the click on the notification, define a notificationclick event handler.

For example:

self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  event.waitUntil(self.clients.openWindow(YOUR_URL_HERE));
});
like image 179
Marco Castelluccio Avatar answered Sep 18 '22 21:09

Marco Castelluccio