问题
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