Firebase 云消息传递未以正确格式为 iOS 通知内容发送 aps 有效负载 &服务扩展 [英] Firebase Cloud Messaging not sending aps payload in correct format for iOS Notification Content & Service Extensions
问题描述
我正在尝试使用 Firebase 实现通知.当应用程序在后台或前台时正确接收通知.因此,基本机制正在发挥作用.
现在我已经向应用添加了内容扩展和服务扩展.当我使用本地通知时,内容扩展有效,但就可选字段而言,Firebase 消息负载似乎不正确.这是我的控制台图像的链接:
这里是遇到的 Firebase 远程通知负载(为了匿名编辑了一些很长的 Google 数字:
<代码>{aps ={警报 ={body = "尤里卡!11";title = "病人情况不好";};};类别 = 提供者主体面板;gcm.message_id = 0:149073;gcm.n.e = 1;google.c.a.c_id = 2825604;google.c.a.e = 1;google.c.a.ts = 149073;google.c.a.udt = 0;可变内容 = 1;}
类别"和可变内容"似乎不在正确的位置.它们应该在 aps 负载中.
如何将这些选项包含在有效负载中,以便我的应用程序可以正确解析它并将其与内容和服务扩展连接?
首先,我要提到 FCM 有两种类型的消息负载.notification
和 data
.在此处查看文档
通过 Firebase 通知控制台发送通知时,它将被视为 notification
负载.但是,如果您添加自定义数据,它会将其作为自定义键值对添加到负载中.
例如,在您的帖子中,FCM 负载应如下所示:
<代码>{通知": {"body": "尤里卡!","title": "病人情况不好"},数据": {"category": "provider-body-panel",可变内容":真,click_action":提供者主体面板"}}
怎么了?
click_action
应该在notification
内.mutable-content
应该是mutable_content
(注意下划线)并且应该与notification
处于同一级别>.- (这个我可能误解了,但是)FCM没有
category
参数,click_action
已经对应了它.
在此处查看参数的文档.>
目前无法在使用 Firebase 通知控制台时设置 click_action
和 mutable_content
的值.您必须自己构建有效负载,如下所示:
<代码>{"to": "",mutable_content":真,通知": {"body": "尤里卡!","title": "病人情况不好",click_action":提供者主体面板"}}
然后从您自己的应用服务器发送.您也可以通过 使用邮递员或cURL>
I'm trying to implement notifications using Firebase. The notification is received correctly when the app is in the background or foreground. So, the basic mechanics are working.
Now I've added Content Extensions and Service Extensions to the app. The Content Extension works when I use a local notification, but the Firebase message payload seems incorrect as far as the optional fields are considered. Here is a link to an image of my console:
And here is the Firebase remote notification payload that comes across (with some of the long Google numbers edited for anonymity:
{
aps =
{
alert =
{
body = "Eureka! 11";
title = "Patient is not doing well";
};
};
category = provider-body-panel;
gcm.message_id = 0:149073;
gcm.n.e = 1;
google.c.a.c_id = 2825604;
google.c.a.e = 1;
google.c.a.ts = 149073;
google.c.a.udt = 0;
mutable-content = 1;
}
It appears that the "category" and "mutable-content" are not in the correct place. They should be in the aps payload.
How can I get those options to be in the payload so that my app can correctly parse it and connect it with the Content and Service Extensions?
To start off, I'm going to mention that there are two types of message payloads for FCM. notification
and data
. See the documentation here
When sending notifications through the Firebase Notifications Console, it will be treated as a notification
payload. However, if you add in Custom Data, it will add it in the payload as a custom key-value pair.
For example, in your post, the FCM payload should look something like this:
{
"notification": {
"body" : "Eureka!",
"title": "Patient is not doing well"
},
"data": {
"category": "provider-body-panel",
"mutable-content" : true,
"click_action" : "provider-body-panel"
}
}
What's wrong?
click_action
should be insidenotification
.mutable-content
should bemutable_content
(notice the underscore) and should be on the same level asnotification
.- (this one I might've misunderstood, but) There is no
category
parameter for FCM,click_action
already corresponds to it.
See the docs for the parameters here.
It it is currently not possible to set the value for click_action
and mutable_content
when using the Firebase Notifications Console. You'll have to build the payload yourself, something like this:
{
"to": "<REGISTRATION_TOKEN_HERE>",
"mutable_content" : true,
"notification": {
"body" : "Eureka!",
"title": "Patient is not doing well",
"click_action" : "provider-body-panel"
}
}
Then send it from your own App Server. You could also do this by using Postman or cURL
这篇关于Firebase 云消息传递未以正确格式为 iOS 通知内容发送 aps 有效负载 &服务扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!