在通知单击时打开Ionic 3 FCM特定页面

时间:2019-06-30 23:00:25

标签: angular ionic-framework ionic3 firebase-cloud-messaging

我正在使用FCM插件向用户发送通知。我需要知道当用户单击该通知时如何打开特定页面? 。我已经尝试过发送页面onNotifcation,但是它始终无法打开首页。

export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: any = HomePage;

  pages: Array<{title: string, component: any}>;

  constructor(public platform: Platform, private fcm: FCM,  public statusBar: StatusBar, public splashScreen: SplashScreen) {
    this.initializeApp();

  }

  initializeApp() {
    this.platform.ready().then(() => {

          //Notifications
      this.fcm.subscribeToTopic('all');
      this.fcm.getToken().then(token=>{
          console.log(token);
      })
      this.fcm.onNotification().subscribe(data=>{
                this.nav.setRoot(VideoPage); // here i add the root

        if(data.wasTapped){
           //also try there but not working 
          console.log("Received in background");
        } else {
          console.log("Received in foreground");
        };
      })
      this.fcm.onTokenRefresh().subscribe(token=>{
        console.log(token);
      });

this.fcm.unsubscribeFromTopic('marketing');

      //end notifications.

      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }

0 个答案:

没有答案