0

I am very confused on how I can implement push notifications into my ionic project using firebase.

I am trying to implement a push notification sender from the device itself, but currently, the only way I know how to do this is by sending a notification manually via firebase console cloud messaging website.

Is it possible to send push notifications from an Ionic 3 application on one device to other devices on that same application? If so, how should I approach this problem? Could you provide me with links or tutorials on how I could do this?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Try https://google.com – Zoe Mar 14 '18 at 21:29
  • @Zoe Why should we make stackoverflow so unfriendly for new users? – alex Mar 14 '18 at 21:33
  • @Zoe I have already tried Google, YouTube, looked at ionic push documentation, firebase documentation and it has not helped much at all, hence why I am asking here. – Nafis Abdullah Bin Azad Mar 14 '18 at 21:34
  • See https://stackoverflow.com/questions/37435750/how-to-send-device-to-device-messages-using-firebase-cloud-messaging, https://stackoverflow.com/a/39279716/209103, https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html – Frank van Puffelen Mar 14 '18 at 23:20

1 Answers1

0

If you want to send a push notification over firebase you have to something like this (pseudo code):

HttpRequest request = new HttpRequest(POST, "https://fcm.googleapis.com/fcm/send");

// headers
request.addHeader("Content-Type", "application/json");
request.addHeader("Authorization", "key=" + myApplicationFirebaseApiKey);

// data
request.body(mydata);
request.send();

myApplicationFirebaseApiKey is the api key. You can get it from console.firebase.google.com

mydata should contain the target device to and data:

{
  "data" : "UPDATE_AVAILABLE",
  "time_to_live" : 0,
  "to" : "<firebase-device-ID>",
  "priority" : "high"
}

As you can see you need the firebase api key. I recommend you to send such requests from your application server. Otherwise you will have to use the api key in your ionic app code and every one can decompile it and steal the key.

alex
  • 8,904
  • 6
  • 49
  • 75