我想在通知点击时打开我的应用程序的特定页面。(Ionic2)

时间:2017-05-26 14:15:53

标签: android firebase ionic-framework ionic2 firebase-cloud-messaging

考虑这种情况。我有一个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');

   });

 }

}

0 个答案:

没有答案