androidfirebasecordovaionic-frameworkcordova-plugin-fcm

Displaying notifications from Ionic using cordova-plugin-firebase-messaging


We are developing an application using the Ionic Framework and would like to integrate push notifications. We are currently attempting to use the Cordova plugin cordova-plugin-firebase-messaging to handle notifications on Android and iOS. I can see that onMessage is being called when I send a notification but how do I make the notification actually display? At the moment I am just trying to log the response by using

this.fcm.onMessage()
   .subscribe(payload => {
      console.log(payload);
    });

Solution

  • Using Ionic, you can make easy popups with either AlertController

    import { AlertController } from 'ionic-angular';
    
    constructor(private alertCtrl: AlertController) {
    
    }
    
    presentAlert() {
      let alert = this.alertCtrl.create({
        title: 'Low battery',
        subTitle: '10% of battery remaining',
        buttons: ['Dismiss']
      });
      alert.present();
    }
    

    Or toastController

    import { ToastController } from 'ionic-angular';
    
    constructor(private toastCtrl: ToastController) {
    
    }
    
    presentToast() {
      let toast = this.toastCtrl.create({
        message: 'User was added successfully',
        duration: 3000,
        position: 'top'
      });
    
      toast.onDidDismiss(() => {
        console.log('Dismissed toast');
      });
    
      toast.present();
    }