问题描述
我正在用FCM原型化浏览器推送通知。我刚从快速入门复制了示例代码()。消息收到并显示应该是。但是当我尝试修改服务工作者(messaging.setBackgroundMessageHandler)中的消息时,没有任何反应。服务工作者被调用,如果我在该服务工作者中为推送通知实现了一个事件监听器,它会捕获该事件。但是setBackgroundMessageHandler方法永远不会被调用。我在Chrome 54上试了这个。
任何想法,我需要做什么来定制服务工作者的消息? b
非常感谢!
对于遇到同样问题的人来说,答案是:
简短摘要:不要在您的json消息中包含notification元素。
I am prototyping browser push notifications with FCM. I just copied the example code from the quickstart (https://github.com/firebase/quickstart-js/tree/master/messaging). Messages are recieved and displayed as they should be. But when I try to modify the message in the Service Worker (messaging.setBackgroundMessageHandler) nothing happens. The service worker is called, and if I implement an event listener in that service worker for the push notifications, it catches the event. But the method setBackgroundMessageHandler is never called.I am trying this on Chrome 54.
Any ideas what I need to do to customize the message in the service worker?
Thank you very much!
For anyone experiencing the same problem, here is the answer: https://github.com/firebase/quickstart-js/issues/71
short summary: do not include a "notification" element in your json message.
这篇关于firebase云消息传递:setBackgroundMessageHandler不被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!