FCM:无法点击通知 [英] FCM: Cannot click notification
问题描述
我使用的是最近发布的 FCM消息支持推送铬上的通知。当我的应用程序在后台,我得到的通知,但没有任何反应,当我点击通知。如何指定当用户点击通知时应该打开的URL? (我明白如何使用notificationclick事件使用纯服务工作者的概念,我想知道如何使用 我在这里错过了什么? 要处理点击通知,一个 notificationclick 事件处理程序。 例如: 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.) What am I missing here? To handle the click on the notification, define a notificationclick event handler. For example:
这篇关于FCM:无法点击通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
messaging.setBackgroundMessageHandler(function(payload){
var data = payload || {};
var shinyData = decoder.run(data);
$ b console.log('[firebase-messaging-sw.js])收到后台消息',shinyData);
return self.registration.showNotification(shinyData.title,{
body:shinyData.body,
icon:shinyData.icon
})
});
$ p $ self.addEventListener('notificationclick',function(event){
event.notification.close();
event.waitUntil(self.clients.openWindow(YOUR_URL_HERE));
});
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
})
});
click_action
is not one of the possible parameters of the showNotification function.self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(self.clients.openWindow(YOUR_URL_HERE));
});