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();
}
});
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With