【发布时间】:2016-11-15 20:02:47
【问题描述】:
我正在努力实现这一目标:
场景 1
- 用户按回。
- 出现弹出窗口询问用户是否要退出 *
- 用户按回。
- 应用退出*
和
场景 2
用户按回。
- 出现弹出窗口询问用户是否要退出 *
- 用户按下取消
- 弹出窗口关闭
- 用户按回。
- 出现弹出窗口询问用户是否要退出 *
- 用户按下返回
- 应用退出。
我尝试使用registerBackButtonAction 和onHardwareBackButtoncombination 但我无法让退出弹出窗口显示第二次(第二种情况),它只是退出。
这是我现在的代码:
var exitPopupControl = function(event) {
//if I press back again, just go out
$ionicPlatform.onHardwareBackButton(function(event2){
navigator.app.exitApp();
});
if($state.current.name === "app.startseite"){
$ionicPopup.confirm({
title: 'Exit',
template: 'Do you want to exit? <br /><small>Press Back again to exit.</small>'
}).then(function(res) {
if(res) {
navigator.app.exitApp();
$rootScope.exitPopupShowed = false;
} else {
console.log('I choose not to left the app');
$ionicPlatform.registerBackButtonAction(exitPopupControl, 100);
}
});
}
else {
window.history.back();
}
};
$ionicPlatform.registerBackButtonAction(exitPopupControl, 100);
【问题讨论】:
-
我确实像stackoverflow.com/questions/40283209/… 一样处理,但没有确认弹出窗口