1
A
回答
5
export class MyApp{
constructor(public alert: AlertController,public platform: Platform){}
exit(){
let alert = this.alert.create({
title: 'Confirm',
message: 'Do you want to exit?',
buttons: [{
text: "exit?",
handler:() => { this.exitApp() }
}, {
text: "Cancel",
role: 'cancel'
}]
})
alert.present();
}
exitApp(){
this.platform.exitApp();
}
}
如果您想启用后退按钮退出,请为其添加事件监听器并调用exit
函数。
您可以使用this.platform.registerBackButtonAction(this.exit)
。
1
我可以通过自己找到合适的解决方案:
https://forum.ionicframework.com/t/show-a-confirmation-alert-before-app-close-ionic/63313
showedAlert: boolean;
constructor(..., public alertCtrl: AlertController) {
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
this.showedAlert = false;
// Confirm exit
this.platform.registerBackButtonAction(() => {
if (this.nav.length() == 1) {
if (!this.showedAlert) {
this.confirmExitApp();
} else {
this.showedAlert = false;
this.confirmAlert.dismiss();
}
}
this.nav.pop();
});
});
}
confirmExitApp() {
this.showedAlert = true;
this.confirmAlert = this.alertCtrl.create({
title: "Salir",
message: "¿ Esta seguro que desea salir de la aplicación ?",
buttons: [
{
text: 'Cancelar',
handler:() => {
this.showedAlert = false;
return;
}
},
{
text: 'Aceptar',
handler:() => {
this.platform.exitApp();
}
}
]
});
this.confirmAlert.present();
}
相关问题
- 1. 在java中关闭应用程序之前显示烤面包
- 2. SAPUI5-在android中退出应用程序之前显示确认
- 3. 关闭JFrame之前显示提示
- 4. 关闭窗口之前显示提示
- 5. 应用程序当前关闭关闭窗口提示
- 6. 显示通知提醒当应用程序在前台
- 7. 我的应用程序突然显示之前关闭RecyclerView
- 8. 在浏览器关闭时显示提醒,但在注销时关闭时不显示提醒
- 9. 在用户提示“手动关闭”之前卸载WiX呼叫应用程序
- 10. 在提交表单之前添加确认提醒
- 11. 关闭前确认
- 12. 在关闭EC2实例之前提示
- 13. Android:如何在强制关闭应用程序之前显示敬酒?
- 14. 在创建应用程序构件之前显示确认对话框
- 15. 在fancybox之前显示确认框
- 16. 显示用户不能关闭的提醒,在事件中自动关闭
- 17. 关闭Outlook提醒
- 18. 在应用程序退出之前,socketpair端应该关闭吗?
- 19. 想要在应用程序从后台进入前台时显示提醒
- 20. 在webtest之前以编程方式关闭应用程序
- 21. 在数据库刷新之前远程关闭应用程序
- 22. 关闭前提示
- 23. 仅在打开应用程序时才会显示提醒
- 24. 如何在应用程序启动时显示提醒
- 25. 在应用程序处于后台时显示sceen提醒
- 26. 在应用程序中显示提醒时的回拨
- 27. 关闭前确认框
- 28. 在提交表单之前显示确认页面
- 29. 在调用Application.Run()之前关闭(退出)和应用程序?
- 30. 流在程序结束之前关闭
退出偶数页推应用程序,它不应该退出,如果任何页面打开 – rashidnk