【问题标题】:How to create Payload for Rich Text Notification using FCM如何使用 FCM 为富文本通知创建有效负载
【发布时间】:2018-11-03 11:54:59
【问题描述】:

我正在我的一个应用中实现富文本通知。我知道我需要以下格式的有效载荷:

{
  "aps": {
      "alert": {
          "title": "", 
          "body": “”
      },
      "badge": 1,
      "sound": "default",
      "mutable-content": true,
      "content-available": true,
      "category": "defaultCategory"
  },
  "image_url": ""
}

虽然当我尝试使用默认 APNS 流程时我成功了,但是我在使用 FCM 实现它时遇到了一个问题,问题是我没有收到密钥:

mutable-content: 1
category: defaultCategory

我对此进行了探索,发现了一个 url FCM rich push notification payload for iOS ,我也尝试使用提到的键。

"mutable_content": true,
"click_action": defaultCategory,

但即使使用这些我也没有得到正确的结果。我在最终更改后收到的当前有效负载是:

{
    gcm.notification.category: defaultCategory, 
    image: /r/u/rustyredsmall.jpg, 
    type_id: XMH677878912-L-Blue, 
    type: Product, 
    aps: {
        alert =     {
           body = "new product notification message2018-05-24 00:00:00";
           title = "Product Notification";
        };
       badge = 1;
       sound = default;
    }, 
    0: {"mutable_content":true}, 
    gcm.message_id: 0:1527142412430945%98b85c5198b85c51
}

任何建议,我怎样才能获得正确的有效载荷?

【问题讨论】:

  • 您的有效载荷结构不正确,这可能是因为它最初没有正确构建。你有用于构建有效载荷的代码或过程吗?如果是这样,您可以将其包含在问题中吗?存在许多问题,因为它包括默认值、数组和其他一些在结构中没有正确值或位置的项目。哦 - 你应该调查一下声音键的值,因为 default 这个词可能是事情出错的地方。那应该是引用文本 "default"

标签: ios swift firebase push-notification firebase-cloud-messaging


【解决方案1】:

我调试了问题并成功解决了问题,服务器端的密钥放置存在一些问题。我们在服务器端创建了有效负载:

{
    "to”: “xyz”,
    "mutable_content": true,
    "notification":
        {
            "body": “this is the message body.“,
            "title": “tiltle text”,
            "sound": "default",
            "badge": 1,
            "click_action": "defaultCategory"
        },
    "data":
        {
            "type": "Category",
            "typeId": "74",
            "redirect_title": "",
            "image_url": "\/d\/r\/dress_16.jpg",
            "notification_id": "1"
        }
}

FCM 将此payload 格式化,并以如下格式发送到移动端:

{
    gcm.message_id: “0:1527233474081223%98b85c5198b85c51”, 
    aps: {
        alert: {
            body: "new product notification message2018-05-24 00:00:00";
            title: "Product Notification";
        };
        badge: 1;
        category: “defaultCategory”;
        mutable-content: 1;
        sound: “default”;
    }, 
    notification_id: 11, 
    typeId: “XMH677878912-L-Blue”, 
    image_url: “/r/u/rustyredsmall.jpg”, 
    type: “Product”, 
    redirect_title: “Midi Dress-L-Blue”
}

【讨论】:

  • 天啊!你是救生员。这---> "click_action": "defaultCategory" 参数为 "category":"defaultCategory" 对我有用...非常感谢!
猜你喜欢
  • 2016-09-21
  • 2017-07-20
  • 1970-01-01
  • 2017-05-26
  • 1970-01-01
  • 1970-01-01
  • 2017-12-13
  • 2020-04-20
  • 2017-07-23
相关资源
最近更新 更多