Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

javascript - How to leverage notificationclick and background message handling using @angular/fire?

I would like to leverage push notification for notification click and background message handling with Firebase Service Worker using Angular PWA's SwPush in order to replace these following code in my firebase-messaging-sw.js:

importScripts('https://www.gstatic.com/firebasejs/<firebase-version-here>/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/<firebase-version-here>/firebase-messaging.js');

firebase.initializeApp({
  ...
});

const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function(payload) {
  ...
});

// Listener when click push notification
self.addEventListener('notificationclick', function (event) {
  ...
});

Here is my dependency version:

  • Angular 8
  • firebase v6.4.2
  • @angular/fire v5.2.0
  • @angular/service-worker v10.0.7

What I have done so far is following this guideline from @angular/fire. As far as I know, the Firebase Service Worker is supposed to register automatically. But when I subscribe to notificationClicks, nothing happened.

this.swPush.notificationClicks.subscribe(...);

Could you please advise what I am missing? If you need more information, please let me know :)

ps. Everything looks good on foreground notification.

question from:https://stackoverflow.com/questions/65841599/how-to-leverage-notificationclick-and-background-message-handling-using-angular

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...