Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use navigator.app.exitApp() to exit application in cordova on iOS platform?

Tags:

cordova

I have an application built using cordova but I don't know how to add exit/stop function to exit the application.After looking around in google and other sites I got clue to use navigator.app.exitApp() but it didn't work for me. How can I solve this?

here is my code:

function onDeviceReady() {
            var network = navigator.connection.type;

            if (network === 'none') {


                    $cordovaDialogs.confirm('Attention' + '\n' + 'You have no internet connection', '', ['Review Settings', 'Exit'])
                        .then(function(buttonIndex) {
                            // no button = 0, 'OK' = 1, 'Cancel' = 2
                            var btnIndex = buttonIndex;
                            if (btnIndex == 1) {
                                $state.go('register');
                            } else {
                                navigator.device.exitApp();
                            }
                        });
like image 675
Raman Rakhra Avatar asked Sep 27 '22 17:09

Raman Rakhra


2 Answers

navigator.device.exitApp() does not work in iOS...it is ignored. It may in Android (typically with some mods, but that's another issue).

You can modify an existing plugin or create your own plugin and add a method to call native ObjC exit(0) or [[NSThread mainThread] exit]. Apple frowns upon including a way for user's to exit an iOS app.

like image 90
gro Avatar answered Sep 30 '22 08:09

gro


Don't. It's not a part of how iOs apps work. And if you use it there is a good change your App will not be approved in the Apple Review process and will be rejected from the App Store.

Other SO answer: Exit App

Apple itself: Themes & UI

like image 37
Flummox - don't be evil SE Avatar answered Sep 30 '22 08:09

Flummox - don't be evil SE