应用程序退出离子3时的触发功能 [英] Trigger function on app exit Ionic 3
问题描述
所以我正在为我的应用程序寻找3种情况...
So I’m looking for 3 scenarios for my application…
当用户在应用程序中时,一切正常(很明显)
When the user is in the app everything works (obviously)
当应用程序退出或置于后台(用户按下主屏幕按钮)时,我要触发功能A
When the app is either quit or put in the background (user presses home button) I want to trigger Function A
当用户在应用程序中并只是锁定手机(不退出应用程序或其他任何东西)时,我想触发功能C.
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.
我知道apache和所有功能的暂停"功能,但我最担心的是第三个场景
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?
推荐答案
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
});
不幸的是,这在iOS上不起作用
Unfortunately this do not work on iOS
这篇关于应用程序退出离子3时的触发功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!