Firebase 推送通知和 FCM 消息有什么区别? [英] What is the difference between Firebase push-notifications and FCM messages?

查看:29
本文介绍了Firebase 推送通知和 FCM 消息有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Heloo,我正在构建一个应用程序,通过 Firebase 控制台使用推送通知.我想知道简单的推送通知和云消息有什么区别?来自云消息的消息是数据消息(有键和值),而通知只是没有键和值的文本吗?我说的对吗?

Heloo, I am building an app where I am using push notifications via Firebase Console. I want to know what is a difference between simply push-notification and cloud message? Is it that messages from cloud messaging are data messages(have key and value) and notifications are just text without key and value?Am I right?

推荐答案

Firebase API 有两种类型的消息,他们称之为:

Firebase API has two types of messages, they call them:

  • 通知
  • 数据
  1. 通知 - 仅当您的应用程序处于 background/killed 或传递到 onMessageReceived() 时,消息才会直接发送到 Android 的通知托盘如果您的应用位于前台,则方法.
  1. notification - messages that goes directly to Android's Notification tray only if your application is in background/killed or gets delivered to onMessageReceived() method if your app is in foreground.

示例:

{
    "notification" : { "body" : "Hi"}
}

  1. 数据负载 - 无论您的应用程序是在前台还是后台还是被杀死,这些消息都将始终传递给 onMessageReceived() 方法.
  1. data payload - Doesn't matter whether your application is in forground or background or killed, these messages will always be delivered to onMessageReceived() method.

示例:

{
    "data" : { "message" : "Hi", "whatever_key": "value"}
 }

参考链接

重要提示:您无法从 Firebase 控制台 发送数据负载消息,控制台仅发送通知消息.但是使用 API,您可以发送两种类型的消息.

IMPORTANT : You can't send data payload messages from Firebase Console, Console only delivers notification message. However using API you can send both type of messages.

要发送数据负载消息,您必须发出 curl 请求:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

您可以从 firebase 控制台获取服务器密钥 (AIzaSyZ-1u...0GBYzPu7Udno5aA):您的项目 -> 设置 -> 项目设置 -> 云消息传递 -> 服务器密钥

You can get the server key (AIzaSyZ-1u...0GBYzPu7Udno5aA), from firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key

这篇关于Firebase 推送通知和 FCM 消息有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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