//身体就像这样
{
"to":
"/topics/NEWS"
,
"data":{
"extra_information": "This is some extra information"
},
Run Code Online (Sandbox Code Playgroud)
//我需要提供的通知
"notification":{
"title": "ChitChat Group",
"text": "You may have new messages",
"click_action":"ChatActivity"
}
}
Run Code Online (Sandbox Code Playgroud) 我正在关注本教程,到目前为止我有适用于网络浏览器的通知(在 Chrome 中测试)
但我不知道如何通过有效负载发送图标,到目前为止我所做的是发送请求正文,如下所示(我正在使用 firebase 云函数):
{
'message': {
token,
'notification': {
title,
body,
icon // <-- added the icon
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试在消息负载中添加图标,当我向 google FCM URL 发送帖子时,我会收到错误的请求。
它可以在不将图标属性添加到有效负载的情况下工作,显然,这就是错误,问题又是如何将有效负载中的图标发送到工作。
谢谢
编辑,我正在发布我的帖子功能:
async function notification(messageBody) {
const api = 'https://fcm.googleapis.com/v1/projects/{projectID}/messages:send';
const accessToken = await getAccessToken();
const response = await fetch(api, {
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': `Bearer ${accessToken}`
},
method: 'POST',
body: messageBody
});
return response;
}
Run Code Online (Sandbox Code Playgroud)