Home > database >  Push Notifications for Ionic Framework
Push Notifications for Ionic Framework

Time:01-20

Back again. I'm writing a mobile application for Android and iOS using ionic framework. It is working well so far as I have the flexibility I want to write it. I've come up to the point of having to add push notifications and chose to use the Azure Notification Service seeing as I'm hosting everything else in Azure too.

I've followed the examples in the repo as suggested by Microsoft here but they are out of date. They are all for Ionic 4 and it is now Ionic 6. The phone-gap plugin is now out of support and the example code doesn't work (due to the fact that the framework has now moved on).

I'm hoping and praying that someone has an example they could share of how to achieve this.

Thanks in advance.

CodePudding user response:

Maybe it's not the best solution, but it works:

In case you cannot manage to get Azure Notification Service working, you can connect your Azure service to Google push notifications API.

You only have to make a post request to https://fcm.googleapis.com/fcm/send.

https://firebase.google.com/docs/cloud-messaging/send-message#send_using_the_fcm_v1_http_api

Here you have an example that I've used:

#!/bin/bash

curl -d '{
  "to": "USER_NOTIFICATIONS_TOKEN",
   "notification": {
   },
   "data":
    {
      "data1":"qwertyu",
      "data2":"4567893",
    }
}' \
-i -H "Application/json" \
-H "Content-type: application/json" \
-H "Authorization: key=MY_SECRET_KEY" \
-X POST https://fcm.googleapis.com/fcm/send

Then, to receive the notifications by cordova, you can use this library:

https://github.com/Maxim-Kolmogorov/cordova-plugin-push-notifications
  • Related