Ionic PWA: Notifications app closed

0

Hello everyone. I searched a lot for this problem where I'm stuck for a week. I have an Ionic PWA project that gets some Firebase notifications, I can receive the notifications without any problem and can get the payload in the foreground (app is open), but I can not get the payload when the PWA is closed and I do not I discovered what is happening, so I came here to ask the masters to help me.

This is an excerpt from the firebase-messaging-sw.js code:

messaging.setBackgroundMessageHandler(function(payload) {
var notificationTitle = 'Teste';
var notificationOptions = {
  body: 'Background Message body.',
  tag: 'campanhas',
  data: payload.data,
  icon: 'https://firebasestorage.googleapis.com/v0/b/hemotomobile-edeb9.appspot.com/o/logo.png?alt=media&token=4a9fc487-b8cf-4d3c-875c-774454ff6f50'
};


return self.registration.showNotification(notificationTitle,
 notificationOptions);
});

self.addEventListener('notificationclick', function(event) {
event.notification.close();

event.waitUntil(clients.matchAll({
  type: "window"
}).then(function(clientList) {
 for (var i = 0; i < clientList.length; i++) {
   var client = clientList[i];
   if (client.url == '/' && 'focus' in client)
   return client.focus();
 }
 if (clients.openWindow)
   return clients.openWindow('/');
 }));
});

At the provider who handles notifications:

public receiveMessage() {
  console.log('notification')
  this.messaging.onMessage((payload) => {
    console.log('payload',payload)
  });
}

I call this provider on my tabs.ts page

ionViewDidLoad(){
 this.notification.receiveMessage()
}

Has anyone ever been through this?

    
asked by anonymous 21.06.2018 / 21:51

0 answers