I am using phonegap to develop one of my iPhone app. In the index.html page I am implementing a small javascript code just to check if the Internet is available or not inside the onBodyLoad() function as below:
function onBodyLoad() {
if (!navigator.onLine) {
alert('offline');
}
document.addEventListener("deviceready",onDeviceReady,false);
//alert("here!");
}
This just work fine but I want to exit from the application when user taps the “Ok” button of that alert message.
I tried the add navigator.device.exitApp() after the alert but did not work.
How can I exit from the application after tapping the “OK” button from the alert message?
Thanks
navigator.device.exitApp()is not supported on iOS as Apple is pretty down on apps closing themselves.It is possible I believe by setting the
UIApplicationExitsOnSuspendboolean to YES in your applications info plist (in a PhoneGap application this is in Supporting Files -> -info.plist).See:
https://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
Specifically: “Opting out of Background Execution”