how to check app running in foreground or background in ionic4

   //Subscribe on pause i.e. background

        this.platform.pause.subscribe(() => {

          //Hello pause

          if(localStorage.getItem("LOG_IN") == "YESORANGE") {

                this.loginprofile=  JSON.parse(localStorage.getItem("Loginprofile"));

                this.api.UserLoginStatus({

                  loginUserId: this.loginprofile.Id,

                  status:"online"

                }).subscribe((res: any) => {

                  console.log(res);

                })

              }

        });


 

        

        //Subscribe on resume i.e. foreground 

        this.platform.resume.subscribe(() => {

          if(localStorage.getItem("LOG_IN") == "YESORANGE") {

                this.loginprofile=  JSON.parse(localStorage.getItem("Loginprofile"));

                this.api.UserLoginStatus({

                  loginUserId: this.loginprofile.Id,

                  status:"offline"

                }).subscribe((res: any) => {

                  console.log(res);

                })

              }

        });

       }

     

Comments

Popular posts from this blog

How to Add Firebase Analytics to Your NativeScript Mobile App

how to split array as per fixed length, and ionic two dates differences in min,seconds,hours