Firebase Cloud Messaging不以正确的格式发送iOS通知内容和服务扩展的aps负载

cru*_*sty 7 apple-push-notifications ios firebase firebase-cloud-messaging

我正在尝试使用Firebase实施通知.当应用程序位于后台或前台时,会正确接收通知.所以,基本机制正在发挥作用.

现在我已将Content Extensions和Service Extensions添加到应用程序中.内容扩展在我使用本地通知时有效,但只要考虑可选字段,Firebase消息有效内容就会显示不正确.这是我的控制台图像的链接:

具有可变内容和类别选项的Firebase控制台图像

以下是Firebase远程通知有效负载(为了匿名而编辑了一些长Google数据:

{
    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;
}
Run Code Online (Sandbox Code Playgroud)

似乎"类别"和"可变内容"不在正确的位置.它们应该在aps有效载荷中.

如何让这些选项在有效负载中,以便我的应用程序可以正确解析它并将其与内容和服务扩展连接?

AL.*_*AL. 8

首先,我要提一下FCM有两种类型的消息有效负载.notificationdata.请参阅此处的文档

通过Firebase Notifications Console发送通知时,它将被视为notification有效负载.但是,如果添加自定义数据,它会将其作为自定义键值对添加到有效内容中.

例如,在您的帖子中,FCM有效负载应如下所示:

{
    "notification": {
        "body" : "Eureka!",
        "title": "Patient is not doing well"
    },

    "data": {
        "category": "provider-body-panel",
        "mutable-content" : true,
        "click_action" : "provider-body-panel"
    }
}
Run Code Online (Sandbox Code Playgroud)

怎么了?

  • click_action应该在里面notification.
  • mutable-content应该是mutable_content(注意下划线),并应在同一水平notification.
  • (这个我可能会误解,但是)categoryFCM 没有参数,click_action已经对应了它.

请在此处查看参数的文档.

目前无法使用Firebase Notifications Console 设置值click_actionmutable_content使用Firebase Notifications Console.您必须自己构建有效负载,如下所示:

{
    "to": "<REGISTRATION_TOKEN_HERE>",
    "mutable_content" : true,
    "notification": {
        "body" : "Eureka!",
        "title": "Patient is not doing well",
        "click_action" : "provider-body-panel"
    }
}
Run Code Online (Sandbox Code Playgroud)

然后从您自己的App Server发送它.您也可以使用PostmancURL 完成此操作