Firebase Cloud Messaging无法以iOS格式的正确格式发送aps负载通知内容&服务扩展 [英] Firebase Cloud Messaging not sending aps payload in correct format for iOS Notification Content & Service Extensions

查看:724
本文介绍了Firebase Cloud Messaging无法以iOS格式的正确格式发送aps负载通知内容&服务扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Firebase实现通知。当应用程序处于后台或前台时,会正确接收通知。所以,基本的力学工作。

现在我已经将内容扩展和服务扩展添加到应用程序。内容扩展在我使用本地通知时起作用,但就可选字段而言,Firebase消息负载似乎不正确。这是一个链接到我的控制台的图像:



这里是Firebase远程通知有效内容(有些长数字的Google编辑是匿名的:

  {
aps =
{
alert =
{
body =Eureka!11;
title =病人做得不好;
};
};
category = provider-body-panel;
gcm.message_id = 0:149073;
gcm.ne = 1;
google.cac_id = 2825604;
google.cae = 1;
google.cats = 149073;
google.caudt = 0;
mutable-content = 1;
}

看来类别和可变内容不在正确的位置,它们应该在aps有效载荷中。

我怎样才能得到这些选项在有效载荷,以便我的应用程序可以正确解析它,并将其与内容和服务扩展连接?

解决方案

我将要提到FCM有两种类型的消息有效载荷。 通知数据。请参阅文档



通过Firebase通知控制台发送通知时,它将被视为通知有效内容。但是,如果您添加自定义数据,则会将其作为自定义键值对添加到有效内容中。

例如,在你的帖子,FCM有效载荷应该是这样的:

  {
notification:{
body:Eureka!,
title:病人做得不好

$ bdata:{
category :provider-body-panel,
mutable-content:true,
click_action:provider-body-panel
}
}

有什么不对?


  • click_action 应位于通知中。

  • mutable-content 应该是 mutable_content (注意下划线)并且应该在 >作为通知

  • (这个我可能会被误解,但是 FCM的code> category 参数, click_acti



请参阅文档以了解 here



它是目前无法在使用Firebase通知控制台时设置 click_action mutable_content 的值。您必须自己构建有效内容,如下所示:

  {
to:< REGISTRATION_TOKEN_HERE>,
mutable-content:true,
notification:{
body:Eureka!,
title:Patient is not做得好,
click_action:provider-body-panel
}
}

然后从您自己的应用程序服务器发送它。你也可以通过使用邮递员 cURL p>

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 inside notification.
  • mutable-content should be mutable_content (notice the underscore) and should be on the same level as notification.
  • (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 Cloud Messaging无法以iOS格式的正确格式发送aps负载通知内容&amp;服务扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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