【问题标题】:Sending remote notifications to all users using FCM and React Native使用 FCM 和 React Native 向所有用户发送远程通知
【发布时间】:2020-12-29 20:54:45
【问题描述】:

我正在使用react-native-push-notifications npm 包将本地通知传递给用户。由于本地通知只会影响一个用户,我必须为所有用户使用远程通知服务。但我已经阅读了指南,其中大多数都告诉我们必须登录 FCM 控制台并从那里发送通知。

但是,在我的应用程序的上下文中,我试图以编程方式从应用程序向所有已安装该应用程序的用户发送通知。是否可以使用react-native-push-notification 发送给所有用户而不直接从 FCM 发送?

本地通知的当前代码

 const localNotification = () => {
  PushNotification.localNotification({
    autoCancel: true,
    largeIcon: "ic_launcher",
    smallIcon: "ic_notification",
    bigText: "Hi, user. You have a new order",
    color: "green",
    vibrate: true,
    vibration: 300,
    title: "New Order",
    message: "Received a new order",
    playSound: true,
    soundName: 'default',
    actions: '["Accept", "Reject"]',
  });
 };

此通知仅影响一位用户。由于无法每次都登录 FCM 并发送通知,因此如何向所有用户发送相同的信息。

【问题讨论】:

    标签: javascript reactjs react-native firebase-cloud-messaging


    【解决方案1】:

    没有安全的方法可以直接从您的应用程序向其他用户发送消息,更不用说向所有其他用户发送消息了。如果可能的话,任何人都可以向您应用的任何用户发送任何消息,这将是一个巨大的安全风险。

    因此,用户发送消息必须在受信任的环境中进行,例如 Firebase 控制台、您控制的服务器或 Cloud Functions。有关更多信息,请参阅How to send one to one message using Firebase Messaging

    没有公共 API 可以向已安装该应用的所有用户发送消息。这样做的唯一内置选项是通过 Firebase 控制台。在代码中模拟此功能的最简单方法是为所有设备订阅特定主题(例如/topics/all)。有关这方面的更多信息,请参阅:How do you send a Firebase Notification to all devices via CURL?FCM (Firebase Cloud Messaging) how to send to all Phones?

    【讨论】:

      猜你喜欢
      • 2021-02-15
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多