Trigger function on app exit Ionic 3

爱⌒轻易说出口 提交于 2019-12-08 07:37:18

问题


So I’m looking for 3 scenarios for my application…

When the user is in the app everything works (obviously)

When the app is either quit or put in the background (user presses home button) I want to trigger Function A

When the user is in the app and simply locks there phone (doesn’t exit the app or anything) , I want to trigger Function C.

I'm aware of the Pause functionality with apache and all,but I'm most worried about the 3rd scenerio

Can someone help me differentiate the 3 scenarios above?


回答1:


You can use the background mode: https://ionicframework.com/docs/native/background-mode/

    this.backgroundMode.on('activate').subscribe(() => {
      if(this.backgroundMode.isScreenOff()){
        //Here the app is in background and the screen is off
      }else
        //Here the user just pressed home button
    });

Unfortunately this do not work on iOS



来源:https://stackoverflow.com/questions/49211770/trigger-function-on-app-exit-ionic-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!