Flutter sendMessage()中的Firebase消息传递 [英] Firebase Messaging in flutter sendMessage()

查看:21
本文介绍了Flutter sendMessage()中的Firebase消息传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 Flutter 程序员,在我的项目中使用 node.js 推送通知 Firebase 云消息传递我刚刚发现flutter的firebase_Messaging包中有一个名为sendMessage的方法,但我到处寻找文档,我尝试了一切以找出它是如何工作的,但一无所获.

I am a flutter programmer and I use in my projects when it comes to pushing notifications Firebase cloud messaging using node.js I just discovered that there is a method called sendMessage in the firebase_Messaging package in flutter but I looked every where for documentation and I tried everything to find out how it works but got nothing.

这就是包提供的所有信息:

That's all what the package offers as information:

所以如果有人以前使用过它或者可以帮助我理解它,我将非常感激它<3

so if anyone used it before or can help me to understand it I would really appreciate it <3

推荐答案

不幸的是,这种方法并没有像你想象的那样做:它不是通过 FCM 将消息从一个设备直接发送到另一个设备,而是一种替代方法这些天不经常使用的协议(afaik).

Unfortunately this method does not do what you might think it does: it is not for sending messages from one device directly to another device through FCM, but rather an alternative protocol that is infrequently used these days (afaik).

FlutterFire 文档描述了 sendMessage方法为:

The FlutterFire documentation describes the sendMessage method as:

向 FCM 服务器发送一个新的 RemoteMessage.仅限 Android.

Send a new RemoteMessage to the FCM server. Android only.

很遗憾,这遗漏了一些关键细节,因此我建议您同时查看 Firebase 网站上的 Android 文档,该文档包含在 发送上游消息,开头是:

Unfortunately that is missing a few crucial details, so I recommend also checking out the Android documentation on the Firebase site, where this is covered under sending upstream messages, which starts with:

如果您的应用服务器实现了 XMPP 连接服务器协议,它可以接收从用户设备到云端的上游消息.

If your app server implements the XMPP Connection Server protocol, it can receive upstream messages from a user's device to the cloud.

还是有点模糊,但继续阅读它还提到:

Still a bit vague, but keep reading it also mentions:

在应用服务器上接收 XMPP 消息

当 FCM 接收到来自客户端应用的上游消息传递调用时,它会生成必要的 XMPP 节以发送上游消息.FCM 添加 category 和 from 字段,然后向应用服务器发送如下节:

When FCM receives an upstream messaging call from a client app, it generates the necessary XMPP stanza for sending the upstream message. FCM adds the category and from fields, and then sends a stanza like the following to the app server:

这里的关键是提到了一个应用服务器.正如许多地方所解释的那样:无法直接从一台设备向另一台设备发送消息,因为这样做会允许任何用户向任何其他用户发送他们想要的任何消息,这是一个安全风险.

The key here is the mention of an app server. As many places explain: there is no way to directly send messages from one device to another, as doing so would allow any user to send any message they want to any other user, which is a security risk.

您找到的 sendMessage 方法允许您将消息发送到 FCM 基础架构,然后将其转发到您的应用服务器.如今,它已不再使用,因为 Cloud Functions 等工具提供(至少等效且可能更好)可扩展性和更好的灵活性.

The sendMessage method you found allows you to send a message to the FCM infrastructure, which then forwards it to your app server. It isn't much used anymore these days, as tools like Cloud Functions offer (at least equivalent and probably better) scalability with better flexibility.

这篇关于Flutter sendMessage()中的Firebase消息传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆