我想向所有设备发送通知,我如何使用 fcm http 来做到这一点。
我使用的端点:https://fcm.googleapis.com/fcm/send
这是我尝试过的。
{
notification: {
title: "Daily motivation!",
body: "The greatest glory in living lies not in never falling, but in rising every time we fall. - Nelson Mandela",
tag: "DAILY_QUOTE"
},
collapse_key: "dailyquote"
};
我也试过条件:
{
notification: {
title: "Daily motivation!",
body: "The greatest glory in living lies not in never falling, but in rising every time we fall. - Nelson Mandela",
tag: "DAILY_QUOTE"
},
condition: "!('nothingreally' in topics)"
collapse_key: "dailyquote"
};
标题:
{
"Content-Type": "application/json",
"Authorization": "key=" + myApiKey
}
虽然,当我发送到特定的 registration IDs
时它运行良好,但是当我想发送到所有设备时它不起作用。我错过了什么吗?
答案 0 :(得分:0)
您可以按照以下方法进行操作。
获取设备的 FCM 令牌。
在主题下注册(订阅)FCM 令牌(例如 - daily-motivational-quotes)。
向主题发送通知(例如 - daily-motivational-quotes)
https://fcm.googleapis.com/v1/projects/mobiquity-fcm/messages:send
{
"message": {
"topic": "daily-motivational-quotes",
"notification": {
"title": "Daily motivation!",
"body": "The greatest glory in living lies not in never falling, but in rising every time we fall. - Nelson Mandela",
}
}
您可以在一个主题下注册多个设备。
答案 1 :(得分:0)
https://fcm.googleapis.com//v1/projects/<YOUR-PROJECT-ID>/messages:send
Content-Type: application/json
Authorization: bearer <YOUR-ACCESS-TOKEN>
{
"message": {
"topic": "matc`enter code here`hday",
"notification": {
"title": "Background Message Title",
"body": "Background message body"
},
"webpush": {
"fcm_options": {
"link": "https://dummypage.com"
}
}
}
}