Firebase推送通知和FCM邮件有什么区别? [英] What is the difference between Firebase push-notifications and FCM messages?
问题描述
Heloo,我正在构建一个应用程序,通过Firebase控制台使用推送通知。我想知道简单的推送通知和云消息有什么区别?
是否云消息传递的消息是数据消息(具有密钥和值),通知只是文本而没有键和值?我是对吗?
Firebase API有两种类型的消息,他们称之为:
$ h
$只有当您的应用程序处于后台/终止或者被传送到 onMessageReceived()时,
{
notification:{body:Hi}
}
- 数据有效负载 - 无论您的应用程序处于forground或background或杀死状态,这些消息将始终传递到
on MessageReceived()
方法。
示例:
< pre $ {
data:{message:Hi,whatever_key:value}
}
重要提示:您无法从 Firebase Console 控制台仅传递通知消息。但是使用API,您可以发送这两种类型的消息。
$ b
要发送数据有效负载消息,您必须发出一个curl请求:
HTTP POST请求
https://fcm.googleapis.com/fcm/send
Content-Type:application / json
授权:key = AIzaSyZ-1u ... 0GBYzPu7Udno5aA
{data:{
score:5x1,
time :15:10
},
to:bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1 ...
}
您可以从Firebase控制台获取服务器密钥(AIzaSyZ-1u ... 0GBYzPu7Udno5aA):您的项目 - >设置 - >项目设置 - >云消息传递 - >服务器密钥
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 has two types of messages, they call them:
- notification
- data
Explanation:
- 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.
Sample:
{
"notification" : { "body" : "Hi"}
}
- data payload - Doesn't matter whether your application is in forground or background or killed, these messages will always be delivered to
onMessageReceived()
method.
Sample:
{
"data" : { "message" : "Hi", "whatever_key": "value"}
}
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.
To send a data payload message you have to make a curl request:
HTTP POST Request
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..."
}
You can get the server key (AIzaSyZ-1u...0GBYzPu7Udno5aA), from firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key
这篇关于Firebase推送通知和FCM邮件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!