我的应用程序中有以下代码:
$ionicPopup.alert({
title: $scope.header1,
template: 'The was a problem connecting to the server. Please check your internet connection and try again.'
});
ionic.Platform.exitApp()
我注意到的是,在Android中,应用程序会快速退出而不会显示弹出消息。 我想做的是执行
ionic.Platform.exitApp()
用户在弹出窗口中按"确定"按钮后。 在离子弹出窗口中有一些类似于"离开"事件的东西吗?
最好的方法可能是定义您自己的"确定"按钮,而不是利用默认的关闭按钮 - 这样您就可以在用户单击/点击您的按钮时调用ionic.Platform.exitApp()
。
例:
import { AlertController } from 'ionic-angular';
constructor(private alertCtrl: AlertController) {
}
presentAlert() {
let alert = this.alertCtrl.create({
title: YourCustomHeader,
//subTitle: 'optional text',
message: 'The was a problem connecting to the server. Please check your internet connection and try again.',
buttons: [
{
text: 'OK',
handler: () => {
ionic.Platform.exitApp();
}
}
]
});
alert.present();
}
参考: https://ionicframework.com/docs/api/components/alert/AlertController/#usage