1. 程式人生 > >ionic返回鍵雙擊退出

ionic返回鍵雙擊退出

一、準備

二:程式碼

.run(function ($ionicPlatform, $rootScope, $location, $timeout, $ionicHistory, $cordovaToast) {
        $ionicPlatform.ready(function ($rootScope) {
            // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } if (window.StatusBar) { // org.apache.cordova.statusbar required StatusBar.styleDefault(); } }); //雙擊退出
$ionicPlatform.registerBackButtonAction(function (e) { //判斷處於哪個頁面時雙擊退出 if ($location.path() == '/tab/news') { if ($rootScope.backButtonPressedOnceToExit) { ionic.Platform.exitApp(); } else { $rootScope
.backButtonPressedOnceToExit = true; $cordovaToast.showShortTop('再按一次退出系統'); setTimeout(function () { $rootScope.backButtonPressedOnceToExit = false; }, 2000); } } else if ($ionicHistory.backView()) { $ionicHistory.goBack(); } else { $rootScope.backButtonPressedOnceToExit = true; $cordovaToast.showShortTop('再按一次退出系統'); setTimeout(function () { $rootScope.backButtonPressedOnceToExit = false; }, 2000); } e.preventDefault(); return false; }, 101); })