How to wait for on onNotificationOpen if notification is tapped


#1

Hello,

I’m facing logical problem with FCM integration.

As i’m trying to open different page when particular notification is tapped.

But when i open app using taping on notification, my page redirects correctly but then it will again redirect to Intro or Video page as given in platform.ready below.

What I want is, if i open the app using notification then other code will not be executed.

Can anyone please advice. My code of app.component.ts is below.

changepage: any = false;
    this.platform.ready().then(() => {
        // 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();
        this.fcm.onNotificationOpen().subscribe(res=>{
            **//Below is flag to change navigation of page. If notification is tapped then it should not execute condition( if(!this.changepage)) below.**
            this.changepage = true;
            alert(JSON.stringify(res));
            if(res.page=="lostfound")
            {
                this.nav.setRoot(Tagmap,{name: res.name,lattitude:res.lat,longtitude:res.lon});
            }
        }, (error)=>{
            alert(error);
        },
        ()=>{
            alert("complete");
        });
        **// this will alway given false as below statement isn't wait for this.fcm.onNotificationOpen() to execute.**
        alert(this.changepage);
        if(!this.changepage)
        {
            alert("changepage");
            this.ls.getUserid().then((user_id)=> {
                if(user_id == null){
                    this.rootPage = Intro;
                } 
                if(user_id != null) {
                     this.rootPage = VideoPage;
                }
            });
       }
    });

Please advise.

-Naitik