ios - 如何使用 FCM 为富文本通知创建有效负载
问题描述
我正在我的一个应用程序中实现富文本通知。我知道我需要以下格式的有效负载:
{
"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
我对此进行了探索,发现了一个适用于 iOS 的 url FCM 丰富的推送通知有效负载 ,我也尝试使用提到的键。
"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
}
任何建议,我怎样才能获得正确的有效载荷?
解决方案
我调试了问题并成功解决了问题,服务器端的密钥放置存在一些问题。我们在服务器端创建了有效负载:
{
"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”
}
推荐阅读
- python - 在 html 模板中显示使用 django 的 sql 查询的结果
- kubernetes - 如何在 Kubernetes 中通过 HTTPS 公开应用程序(或服务)?
- javascript - 在 React 和 Wordpress 中添加两个 axios get 请求
- java - char Array 到 String 并在字符之间放置点
- python - Python - 字母金字塔
- php - Ajax 调用中的 shell_exec 导致无限循环
- node.js - 如何使用fabric contract-api检索在Hyperledger Fabric中发起交易的用户的身份?
- python - python中for循环的动态嵌套
- bit-manipulation - 使用按位和运算符赋值
- powershell - 将 CSV 字符串附加到电子邮件