cordova app 再按一次退出程序

来源:互联网 发布:网络mg老虎机技巧规律 编辑:程序博客网 时间:2024/05/16 06:23
app.run(["$ionicPlatform","$ionicPopup","$rootScope","$location","$ionicHistory","$ionicViewSwitcher","$timeout"
,function($ionicPlatform,$ionicPopup,$rootScope,$location,$ionicHistory,$ionicViewSwitcher,$timeout) {
$rootScope.backButtonPressed = false;
$rootScope.fn_alert_exitApp = function(msg) {
window.plugins.toast.showWithOptions(
{
message: msg,
duration: "short", // which is 2000 ms. "long" is 4000. Or specify the nr of ms yourself.
position: "bottom",
addPixelsY: -100, // added a negative value to move it up a bit (default 0)
styling: {
horizontalPadding: 60, // iOS default 16, Android default 50
verticalPadding: 30 // iOS default 12, Android default 30
}
},
function(){}, // optional
function(){} // optional
);
};
/*注册返回事件*/
$ionicPlatform.registerBackButtonAction(function(e){
/*根据首页的路由判断是否提示退出*/
if($location.path() =="/index" ){
if ($rootScope.backButtonPressed ) {
ionic.Platform.exitApp();
} else {
$rootScope.backButtonPressed = true;
$rootScope.fn_alert_exitApp('再按一次退出程序哦 ^_^ '); //
$timeout(function () {
$rootScope.backButtonPressed = false;
}, 2000);
}

}else if($ionicHistory.backView()){
$ionicHistory.goBack();
$ionicViewSwitcher.nextDirection("back");
}else{

if ($rootScope.backButtonPressed ) {
ionic.Platform.exitApp();
} else {
$rootScope.backButtonPressed = true;
$rootScope.fn_alert_exitApp('再按一次退出程序哦 ^_^ '); //
setTimeout(function () {
$rootScope.backButtonPressed = false;
}, 2000);
}
}
return false;
},501);//501表示优先级 100~999之间

}]);