)

2.app.component.ts文件

@ViewChild('myNav')nav:Nav;//声明根组件()

3.贴代码

platform.ready().then(()=>{
this.exitApp();
})
publicbackButtonPressed:boolean=false;
exitApp(){
this.platform.registerBackButtonAction(()=>{
//控制modal、系统自带提示框
letoverlay=this.appCtrl._appRoot._overlayPortal.getActive()||this.appCtrl._appRoot._modalPortal.getActive();
if(overlay){
overlay.dismiss();
return;
}
letactiveVC=this.nav.getActive();
letpage=activeVC.instance;
if(page.tabs){
letactiveNav=page.tabs.getSelected();
if(activeNav.canGoBack()){
returnactiveNav.pop();
}else{
returnthis.showExit();
}
}
if(pageinstanceofLoginPage){//查看当前页面是否是登陆页面
this.showExit();
return;
}
this.appCtrl.getActiveNav().pop();//剩余的情况全部使用全局路由进行操作
});
}

//双击退出函数
showExit(){
if(this.backButtonPressed){
this.platform.exitApp();
}else{
this.presentToast();//再按一次退出
this.backButtonPressed=true;
setTimeout(()=>{
this.backButtonPressed=false;
},2000)
}
}
presentToast(){
lettoast=this.toastCtrl.create({
message:'再按一次退出应用',
duration:2000,
position:'top'
});

toast.onDidDismiss(()=>{
console.log('Dismissedtoast');
});

toast.present();
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。

热门推荐

1 要红包拜年祝福语简短
2 l离别祝福语大全简短
3 新年祝福语简短叔叔阿姨
4 谷雨祝福语简短文字
5 长辈祝福语简短小故事
6 公司年会祝福语简短感谢
7 老公生日祝福语简短情话
8 女儿升大班祝福语简短
9 送企业祝福语简短的
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短