简体   繁体   English

FCM消息通知消息和数据消息(用于Web桌面的推送通知)

[英]FCM Message Notification Message and Data Message (Push Notification FOR WEB DESKTOP)

ead up about Data Payload Message and Notification Payload Message in FCM Website. 在FCM网站上了解有关数据有效载荷消息和通知有效载荷消息的信息。 It was in the main FCM messaging page and the only things they emphasized about are IOS and Android. 它在FCM消息传递主页面中,并且他们强调的唯一内容是IOS和Android。

I am working on web push notification and wouldn't be using this for google app and plugin. 我正在研究网络推送通知,并且不会在Google应用和插件中使用它。 So the only way to implement is through service worker and manifest. 因此,唯一的实现方法是通过服务人员和清单。 Can I only use current (Notification message) json message in sw.js file such as this? 我只能在sw.js文件中使用当前的(通知消息)json消息吗?

self.addEventListener('push', function(event) {
 console.log('Push message received', event);
 var title = 'Push message';
 event.waitUntil(
   self.registration.showNotification(title, {
     body: 'Please choose to like or reply',      
     icon: 'images/icon.png',
     tag: 'my-tag',
     actions:[
       {action:"like", title: "Like"},
       {action:"reply", title: "⤻ Reply"}]
   })
 );
});

What if I would like to have different types of messages for different groups? 如果我想为不同的群组提供不同类型的消息怎么办? I do not really have the clue on how to do it in the back end.. It seems like the code above could only show one Notification title? 我在后端没有真正的线索。似乎上面的代码只能显示一个Notification标题?

Extra Note: (There are three ways of app server request such as topic name, device registration token or device group name as I suspect that those are only used for ANDROID and IOS. Please do correct me if I am wrong if I could use these for Web as well as for the data payload message. 额外说明:(应用服务器请求的三种方式,例如主题名称,设备注册令牌或设备组名称,因为我怀疑这些方法仅用于ANDROID和IOS。如果我使用这些错误,请改正我的意见。用于Web以及数据有效载荷消息。

you asked multiple questions in one, Well i am tring to answer your all question one by one. 您一口气问了多个问题,嗯,我想一一回答您的所有问题。

1). 1)。 Can I only use current (Notification message) json message in sw.js file such as this? 我只能在sw.js文件中使用当前的(通知消息)json消息吗?

the code of service worker seem like you have made this based on old implementation(GCM) which will still work even with FCM too but if you want to use FCM's payload then you have to upgrade this service worker code to handle payload to show in notifications see sample code on link https://firebase.google.com/docs/cloud-messaging/js/receive . 服务人员的代码似乎是您基于旧的实现(GCM)进行的,即使在FCM中也可以使用,但是如果您想使用FCM的有效负载,则必须升级此服务人员代码以处理要在通知中显示的有效负载请参阅链接https://firebase.google.com/docs/cloud-messaging/js/receive上的示例代码。

2). 2)。 What if I would like to have different types of messages for different groups? 如果我想为不同的群组提供不同类型的消息怎么办? I do not really have the clue on how to do it in the back end.. It seems like the code above could only show one Notification title? 我在后端没有真正的线索。似乎上面的代码只能显示一个Notification标题?

Service store on client end to handle payload messages and will be same for all clients. 客户端上的服务存储用于处理有效负载消息,并且对于所有客户端都是相同的。 you have to differentiate receiving title while you sending notification. 发送通知时,您必须区分接收标题。 for that you have to segregate FCM registration ids and then have to send different- 2 messages. 为此,您必须分离FCM注册ID,然后必须发送不同的2条消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM