考虑这种情况。我有一个ionic2应用程序,我使用FCM插件进行推送通知。现在让我们说当应用程序在后台时推送通知。用户,在App抽屉中查看通知,然后单击通知以获取更多信息。我希望用户使用this.nav.push(PushPage)导航到特定路径。如何点击通知点击事件?
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({
templateUrl: 'app.html',
providers :[FCM]
})
export class MyApp {
rootPage:any = HomePage;
@ViewChild(NavController) nav;
constructor(platform: Platform, statusBar: StatusBar, splashScreen:
SplashScreen,private fcm: 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');
});
}
}