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

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

问题描述

在搜索文档后,我找不到任何关于如何在不使用外部服务器的情况下使用 FCM 向设备发送消息的信息.

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.

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

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?

推荐答案

更新: 现在可以使用 firebase 云函数作为服务器来处理推送通知.查看他们的文档这里

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.

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

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

...

您需要决定要使用哪种 FCM 连接服务器协议来使您的应用服务器能够与 FCM 连接服务器进行交互.请注意,如果要使用来自客户端应用程序的上游消息传递,则必须使用 XMPP.有关这方面的更详细讨论,请参阅选择 FCM 连接服务器协议.

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.

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

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

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

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

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

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