【发布时间】:2018-02-04 17:45:57
【问题描述】:
根据 react-native-fcm 包,您可以在 FCM 消息传递有效负载的数据对象中包含自定义嵌套对象。
according to this post by the package author
像这样:
var payload = {
data: {
custom_notification: {
title: 'title',
body: 'body',
priority: 'high',
id: 'id',
group: 'group'
}
}
};
这是为了在所有应用程序状态下接收抬头通知,如果您只执行通知负载或数据负载,则不会发生这种情况。
当我在我的云功能中实现此功能时,我收到以下错误:
Error: Messaging payload contains an invalid value for the "data.custom_notification" property. Values must be strings.
所以我不知道其他人如何成功地使用它?
我想知道我的环境是否存在问题,或者是由 firebase 支持(并且在文档中)提供给我的以下测试有效负载错误:
var payload = {
"to":"FCM_TOKEN",
"data": {
"type":"MEASURE_CHANGE",
"body": "test body",
"title": "test title",
"color":"#00ACD4",
"priority":"high",
"id": "id",
"show_in_foreground": true
}
};
我收到以下错误:
Error sending message stringify: {"code":"messaging/invalid-payload","message":"Messaging payload contains an invalid \"to\" property. Valid properties are \"data\" and \"notification\"."}
已经在这几天了,希望我能在这方面得到一些帮助。
提前致谢!
【问题讨论】:
-
尝试使用以下方法对有效负载进行字符串化:body: JSON.stringify({ your json object })
标签: javascript android firebase react-native firebase-cloud-messaging