Consider this scenario. I have an ionic2 app and I am using the the FCM plugin for push notifications. Now let us say a push notification arrives when the app is in the background. User, views the notification in the App drawer and then clicks the notification for further information. I would like the user to navigate to a particular path using this.nav.push(PushPage). How can I tap into the notification click event?I tried something like this.but it did not
app.component.ts
import { Component,ViewChild } from '@angular/core';
import { Platform,NavController,AlertController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { FCM } from '@ionic-native/fcm';
import { HomePage } from '../pages/home/home';
import {PushPage} from '../pages/push/push';
declare var FCMPlugin;
@Component({
template: '<ion-nav #myNav [root]="rootPage"></ion-nav>',
providers :[FCM]
})
export class MyApp {
rootPage:any = HomePage;
@ViewChild('myNav') nav: NavController;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,privatefcm:FCM, private alertCtrl: AlertController) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
fcm.subscribeToTopic('marketing');
fcm.getToken().then(token=>{
})
fcm.onNotification().subscribe(data=>{
if(data.wasTapped){
console.log("Received in background");
this.nav.push(PushPage);
} else {
console.log("Received in foreground");
this.nav.push(PushPage);
};
})
fcm.onTokenRefresh().subscribe(token=>{
this.nav.push(PushPage);
})
fcm.unsubscribeFromTopic('marketing');
});
}
}