Michel
Michel

Reputation: 11755

How to use javascript for sending remote notifications with Firebase?

Here is an issue I am having with Firebase and push notifications.

In a web app, I want a button which sends a remote notification when clicked. This notification is meant to be received by an iOS app working together with my web-app.

The present question is about how to make this work. The web offers some example of how to receive notifications in a web application, but I did not find much about sending one, and this is precisely what I need to do.

Below is the relevant code, the problem is to know how to write the code for the SendNotific() function, and maybe some other details. I hope someone, expert on the subject will be able to provide me with some advice.

<body>
<script>
  // Initialize Firebase.
  var config = {
    apiKey: "myyKeyyy",
    authDomain: "......firebaseapp.com",
    databaseURL: "https://......firebaseio.com",
    projectId: "....",
    storageBucket: "........appspot.com",
    messagingSenderId: "........."
  },
  app = firebase.initializeApp(config);
  db = firebase.firestore(app);
  const messaging = firebase.messaging();

function SendNotific() {
// Code to send a notification.
........
}
</script>

<input type='button' id='PushNotif' style='font-size:20px' value='Send notification!' onClick='SendNotific()'>
</body>

Upvotes: 0

Views: 135

Answers (1)

Suraj Malviya
Suraj Malviya

Reputation: 3783

You cannot send notifications using client, for sending notifications firebase has an Admin SDK which should be used by the application server. Though if you are up to building a serverless app then you should consider Firebase Cloud functions which you can trigger using a HTTP endpoint and the cloud function can handle the notifications sending job.

Upvotes: 1

Related Questions