如何解决如何使用http向所有设备发送fcm通知?
我想向所有设备发送通知,我如何使用 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!",condition: "!('nothingreally' in topics)"
collapse_key: "dailyquote"
};
标题:
{
"Content-Type": "application/json","Authorization": "key=" + myApiKey
}
虽然,当我发送到特定的 registration IDs
时它运行良好,但是当我想发送到所有设备时它不起作用。我错过了什么吗?
解决方法
您可以按照以下方法进行操作。
-
获取设备的 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",}
}
您可以在一个主题下注册多个设备。
,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"
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。