ionic雙擊退出鍵退出APP

來源:互聯網
上載者:User

標籤:

1、安裝外掛程式

Toast is compatible with Cordova Plugman, compatible with PhoneGap 3.0 CLI, here‘s how it works with the CLI (backup your project first!):

Using the Cordova CLI and the Cordova Plugin Registry

$ cordova plugin add nl.x-services.plugins.toast$ cordova prepare

Or using the phonegap CLI

$ phonegap local plugin add nl.x-services.plugins.toast

安裝後可以用命令查看 http://www.cnblogs.com/cuoreqzt/p/4491943.html

 

2、在app中加上js

.run(function ($ionicPlatform, $rootScope, $location, $timeout, $ionicHistory) {        $ionicPlatform.ready(function () {            // 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 && window.cordova.plugins.Keyboard) {                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);            }            if (window.StatusBar) {                // org.apache.cordova.statusbar required                StatusBar.styleLightContent();            }            //雙擊退出            if (window.cordova && window.plugins && window.cordova.plugins.Toast){                $ionicPlatform.registerBackButtonAction(function (e) {                    //判斷處於哪個頁面時雙擊退出                    if ($location.path() == ‘/tab/home‘) {                        if ($rootScope.backButtonPressedOnceToExit) {                            ionic.Platform.exitApp();                        } else {                            $rootScope.backButtonPressedOnceToExit = true;                            cordova.plugins.Toast.showShortTop(‘再按一次退出系統‘);                            setTimeout(function () {                                $rootScope.backButtonPressedOnceToExit = false;                            }, 2000);                        }                    }                    else if ($ionicHistory.backView()) {                        $ionicHistory.goBack();                    } else {                        $rootScope.backButtonPressedOnceToExit = true;                        cordova.plugins.Toast.showShortTop(‘再按一次退出系統‘);                        setTimeout(function () {                            $rootScope.backButtonPressedOnceToExit = false;                        }, 2000);                    }                    e.preventDefault();                    return false;                }, 101);            }        });    })

 

ionic雙擊退出鍵退出APP

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.