【发布时间】:2017-10-10 08:46:35
【问题描述】:
我尝试在我的 Ionic 应用程序中覆盖手机的后退按钮。
如果我不在页面中,此代码允许我打开一个模式来关闭应用程序,否则关闭页面。
但这不允许我关闭打开的模式。如何检测我是否处于关闭模式?
platform.registerBackButtonAction(() => {
let nav = app.getActiveNav();
let activeView: ViewController = nav.getActive();
console.log(activeView);
if(activeView != null){
if(nav.canGoBack()) {
activeView.dismiss();
} else{
let alert = this.alertCtrl.create({
title: this.pdataManager.translate.get("close-app"),
message: this.pdataManager.translate.get("sure-want-leave"),
buttons: [
{
text: this.pdataManager.translate.get("no"),
handler: () => {
this.presentedAlert = false;
},
role: 'cancel',
},
{
text: this.pdataManager.translate.get("yes"),
handler: () => {
this.presentedAlert = false;
this.platform.exitApp();
}
}
]
});
if(!this.presentedAlert) {
alert.present();
this.presentedAlert = true;
}
}
}
});
}
【问题讨论】:
标签: javascript android cordova ionic3