Ionic double eject key to exit the app

Source: Internet
Author: User

1, install the plug-in

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

nl. xservices.plugins.toast$ Cordova Prepare

Or using the PhoneGap CLI

nl. x-services.plugins.toast

After installation, you can use the command to view http://www.cnblogs.com/cuoreqzt/p/4491943.html

2, add JS in the app

. 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 Requiredstatusbar.stylelightcontent (); }            //Double Exit            if(Window.cordova && window.plugins &&window.cordova.plugins.Toast) {$ionicPlatform. registerbackbuttonaction (function(e) {//double-exit when deciding which page to be in                    if($location. Path () = = '/tab/home ') {                        if($rootScope. backbuttonpressedoncetoexit) {ionic.                        Platform.exitapp (); } Else{$rootScope. backbuttonpressedoncetoexit=true; Cordova.plugins.Toast.showShortTop (' Press again to exit the system '); SetTimeout (function() {$rootScope. Backbuttonpressedoncetoexit=false; }, 2000); }                    }                    Else if($ionicHistory. Backview ()) {$ionicHistory. GoBack (); } Else{$rootScope. backbuttonpressedoncetoexit=true; Cordova.plugins.Toast.showShortTop (' Press again to exit the system '); SetTimeout (function() {$rootScope. Backbuttonpressedoncetoexit=false; }, 2000);                    } e.preventdefault (); return false; }, 101);    }        }); })

Ionic double eject key to exit the app

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.