问题描述
我已经建立了一个简单的推送通知站点,如果浏览器在前台,通知就可以到达.
I've set up a simple push notification site, the notifications arrive okay if the browser is in foreground.
如果浏览器在后台,问题就开始了:通知到达两次,一次设置了图像样式和其他设置,另一次只有标题和正文消息.
The problem begins if the browser is in background: the notification arrives twice, one styled with image and other settings set and the other has only title and body message.
Service Worker 的内容:
Content of the service worker:
客户端js:
谢谢!
推荐答案
在 messaging.setBackgroundMessageHandler
事件中加入这一行即可解决问题:
The problem can be solved with adding this line to the messaging.setBackgroundMessageHandler
event:
这样,默认通知将不会显示,您必须在 self.addEventListener
事件中显示您的通知.
This way, the default notification won't show and you have to show your notification in the self.addEventListener
event.
这篇关于如果浏览器在后台,FCM 推送通知会到达两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!