#StackBounty: #ionic-framework #firebase-cloud-messaging Ionic 3 FCM specific page open on notification click

Bounty: 50

I am using FCM plugin to send notification to user. I need to know how can i open specific page when user click on that notification ? . I already try to send page onNotifcation but its not working it always open homepage.

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


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.