当请求不是来自Firebase控制台时,RemoteMessage.GetNotification()返回null? [英] RemoteMessage.GetNotification() returns null when request is not from Firebase Console?
问题描述
我正在测试Firebase Cloud Messaging.
I am testing Firebase Cloud Messaging.
如果我使用Firebase控制台发送消息-在我的代码中,我设置了值的Notification对象-没问题:
If I use a Firebase Console to send a message - in my code I Notification object with values set - not a problem:
public override void OnMessageReceived(RemoteMessage message)
{
base.OnMessageReceived(message);
Firebase.Messaging.RemoteMessage.Notification oNotification;
oNotification = message.GetNotification();
我正在使用 http://requestmaker.com/发送通知-一切正常-它得到发送,我取回messageID.
I am using http://requestmaker.com/ to send a notification - and all works fine - it gets sent and I get back the messageID.
POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Accept: */*
Authorization: key=not-a-real-key0omClYhniZaIAercMVzeFHEG508USi8lud9pxC-SzxAAbR2mflAfVNsfrbrsPJxoFYTr15ytRn9aqWSQXm5x00AOwu2Wl6mWwTcm9l6G
Content-Length: 188
Content-Type: application/x-www-form-urlencoded
但是oNotification = message.GetNotification();
返回null.
问题是-为什么?
But the oNotification = message.GetNotification();
returns null.
The questions is - why?
推荐答案
似乎您正在发送 FCM消息类型.
It seems that you were sending a data
payload instead of a notification
payload. When using the Firebase Console, the message sent is always treated as a notification
payload message (or a combination of both if you added custom key-value pairs in the Advance Options). See FCM Message Types.
使用requestmaker时,您可能仅发送仅data
个有效负载.在您的代码中,您仅处理具有notification
有效负载类型的消息:
It's possible that you were only sending data
-only payloads when using the requestmaker. In your code, you're only handling messages with notification
payload types:
message.GetNotification();
我对Android Xamarin并不十分熟悉,但是通常对FCM并不陌生,还有一种方法可以通过调用
I'm not fully familiar with Android Xamarin, but usually with FCM, there is also a way to get the data
payloads by calling RemoteMessage.getData()
, should you decide to send data
-only payloads.
这篇关于当请求不是来自Firebase控制台时,RemoteMessage.GetNotification()返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!