Brady Shober
Brady Shober

Reputation: 67

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);
    });

Upvotes: 0

Views: 476

Answers (2)

wcjord
wcjord

Reputation: 539

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();
}

Upvotes: 0

somerandomusername
somerandomusername

Reputation: 2025

I guess you have this issue on iOS? If so then it's not a bug. You won't see any notification on iOS devices if the app is running in foreground.

From Apple: If you receive local or remote notifications while your app is running in the foreground, you’re responsible for passing the information to your users in an app-specific way

Upvotes: 1

Related Questions