首页 > 解决方案 > 如何使用 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!",
        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,但是当我想发送到所有设备时它就不起作用了。我错过了什么吗?

标签: androidpush-notificationfirebase-cloud-messagingreact-native-firebase

解决方案


您可以按照以下方法。

  • 获取设备的 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",
       }
}

您可以在一个主题下注册多个设备。


推荐阅读