- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我真的不知道这些东西是怎么回事。
我正在为我的网站正常使用 FCM 网络推送。如果我在前台,我可以在网站上收到消息,如果我在后台,我会收到通知。到现在为止还挺好。
importScripts('https://www.gstatic.com/firebasejs/8.2.5/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.2.5/firebase-messaging.js');
firebase.initializeApp({
...
});
const messaging = firebase.messaging();
问题是firebase-messaging-sw.js的默认配置在后台显示通知,并显示镶边图标。我希望能够自定义此通知并显示我的应用程序图标。然后在网上阅读我发现我需要用onBackgroundMessage()来拦截消息。
importScripts('https://www.gstatic.com/firebasejs/8.2.5/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.2.5/firebase-messaging.js');
firebase.initializeApp({
...
});
const messaging = firebase.messaging();
if (messaging) {
messaging.onBackgroundMessage(payload => {
const notificationTitle = payload.notification.title || payload.data.title;
const notificationOptions = {
body: payload.notification.body || payload.data.subtitle || '',
icon: 'https://firebasestorage.googleapis.com/v0/b/yes-4-web.appspot.com/o/pontonos%2Ficons%2Fandroid-chrome-192x192.png?alt=media&token=35616a6b-5e70-43a0-9284-d780793fa076',
data: payload.data
};
return self.registration.showNotification(notificationTitle, notificationOptions);
});
self.addEventListener('notificationclick', event => {
event.notification.close();
event.waitUntil(clients.matchAll({ type: "window" }).then(function(clientList) {
for (let i = 0; i < clientList.length; i++) {
const client = clientList[i];
if (client.url === '/' && 'focus' in client) {
if (event.notification.data.route) client.href(event.notification.data.route);
return client.focus();
}
}
if (clients.openWindow)
return clients.openWindow(event.notification.data.route || '/');
}));
});
}
问题是现在,当使用 onBackgroundMessage() 时,我会看到两个通知,一个是带有 chrome 图标的原始通知,另一个是带有我的应用程序图标的个性化消息(见图)
最佳答案
这是预期的行为。
github issue
关于使用 onBackgroundMessage() 时,Firebase 网络推送通知被触发两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66697332/
刚刚创建了一个新的 Flutter 应用 最终当我收到通知时尝试打开我的应用程序或显示全屏 Activity (想想电话) 目前只是试图控制台登录通过后台消息处理程序调用的 native 类 当我发送
我真的不知道这些东西是怎么回事。 我正在为我的网站正常使用 FCM 网络推送。如果我在前台,我可以在网站上收到消息,如果我在后台,我会收到通知。到现在为止还挺好。 importScripts('htt
我正在使用 Firebase 推送通知,我想在触发 onBackgroundMessage 时执行我的一些代码。它实际上被触发,因为我在控制台中打印,但我尝试使用几个插件但没有运气。每次我都会收到类似
我正在使用 firebase_messaging 6.0.9与 flutter 1.12.13 .在 repo 的自述文件中:https://pub.dev/packages/firebase_mes
最近我一直致力于将 flutter 与 FCM 连接起来。读书时firebase docs我红了: Handle background messages by registering a onBack
我在应用程序关闭时尝试打开 android Activity 时失败。在下面的代码中看到,当我收到来自 firebase 的数据通知时,当应用程序在后台时,我应该使用 MethodChannel 打开
当应用程序处于后台并且收到通知时,我试图让我的 onBackgroundMessage 执行,但它不执行 myBackgroundMessageHandler。 我做了在可选处理后台消息的文档中写的所
我正在开发一个应用程序,它可以接收来自 firebase 云消息传递的通知。我在收到消息后将其保存在 Hive 中。我有一个通知屏幕,显示从配置单元读取的通知,收到通知后会立即更新。这一直运作良好。
我们正在开发一个加密的聊天应用程序,我们使用 Firebase 消息发送数据通知。在向用户显示实际通知之前,需要在收到数据通知后完成一些客户端逻辑。例如,必须将电话号码转换为本地联系人姓名。这种转换是
我是一名优秀的程序员,十分优秀!