0

I'm using react-native-push-notifications npm package to deliver the local notification to the user. Since the local notification will affect only one user, I have to use the remote notification service for all users. But I have read guides in which most of them are telling like we have to log in to FCM console and send notification from there.

However, in the context of my application, I'm trying to send a notification programmatically from the app to all users who have installed the app. Is it possible using react-native-push-notification to send to all users without sending directly from FCM?

Current code for local notification

 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"]',
  });
 };

This notification is affecting only one user. How can I send the same to all users since it's not possible to log into FCM and send notification each time.

Musthafa
  • 542
  • 1
  • 9
  • 25

1 Answers1

1

There is no secure way to send a message directly from your application to another user, let alone to all other users. If that was possible, anyone could send any message to any of the users of your app, which would be a huge security risk.

So sending a message to a user must happen from a trusted environment, such as the Firebase console, a server you control, or Cloud Functions. For more on this see How to send one to one message using Firebase Messaging

There is no public API to send a message to all users who have installed the app. The only built-in option to do so is through the Firebase console. The easiest way to emulate this functionality in your code, is by subscribing all devices to a specific topic (such as /topics/all). For more on this, see: How do you send a Firebase Notification to all devices via CURL? and FCM (Firebase Cloud Messaging) how to send to all Phones?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807