如何使用Firebase Cloud Messaging将设备发送到设备消息? [英] How to send device to device messages using Firebase Cloud Messaging?

查看:93
本文介绍了如何使用Firebase Cloud Messaging将设备发送到设备消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索文档后,我找不到任何有关如何使用FCM将设备发送到设备消息的信息,而无需使用外部服务器。

例如,if我正在创建一个聊天应用程序,我需要发送推送通知给用户关于未读的消息,因为他们不会一直在线,我不能有一个永久连接到实时数据库因为这样会占用太多的资源。

那么当某个用户B向他/她发送一个聊天消息时,如何向用户A发送推送通知信息?我需要一个外部服务器吗?或者只能使用Firebase服务器来完成?

更新:现在可以使用firebase云端功能作为处理推送通知的服务器。查看他们的文档此处



============



根据文档,您必须实现一个服务器处理设备间通信的推送通知。


在您编写使用Firebase云消息传递的客户端应用程序之前,您必须有一个应用程序服务器符合以下条件:



$ b

您需要决定哪个FCM连接服务器协议s)要用来启用您的应用程序服务器与FCM连接服务器进行交互。请注意,如果您想要使用来自客户端应用程序的上行消息,则必须使用XMPP。有关此更详细的讨论,请参见选择FCM连接服务器协议

如果您只需要从服务器向用户发送基本通知。您可以使用其无服务器解决方案, Firebase通知

查看FCM和Firebase通知之间的比较:
https://firebase.google.com/support/faq/#messaging-difference


After searching the docs I could not find any info on how to send device to device messages using FCM without the use of an external server.

For example, if I was creating a chat application I would need to send push notifications to users about unread messages since they won't be online all the time and I can't have a persistent service in the background that would always be connected to the real time database because that would be too resource heavy.

So how would I send a push notification to a user "A" when a certain user "B" sends him/her a chat message? Do I need an external server for this or can it be done with just Firebase servers?

解决方案

UPDATE: It is now possible to use firebase cloud functions as the server for handling push notifications. Check out their documentation here

============

According to the docs you must implement a server for handling push notifications in device to device communication.

Before you can write client apps that use Firebase Cloud Messaging, you must have an app server that meets the following criteria:

...

You'll need to decide which FCM connection server protocol(s) you want to use to enable your app server to interact with FCM connection servers. Note that if you want to use upstream messaging from your client applications, you must use XMPP. For a more detailed discussion of this, see Choosing an FCM Connection Server Protocol.

If you only need to send basic notifications to your users from the server. You can use their serverless solution, Firebase Notifications.

See a comparison here between FCM and Firebase Notifications: https://firebase.google.com/support/faq/#messaging-difference

这篇关于如何使用Firebase Cloud Messaging将设备发送到设备消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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