As I work on developing an IBM Worklight application, one of my tasks involves checking the SIM details before launching the app. The code snippet below demonstrates this process:
function wlCommonInit() {
WL.Device.getNetworkInfo(function(networkInfo) {
var NetInfo = (networkInfo.carrierName).toUpperCase();
var networkState = (navigator.connection.type).toUpperCase();
if (NetInfo.indexOf("ANDROID") == -1) {
alert("Android Network not available");
WL.App.close();
}
if (networkState == "NONE") {
alert("Data connection not available");
WL.App.close();
}
});
var collectionNameRegistration = 'Registration';
registerUserFirst(collectionNameRegistration);
}
The current issue is that the application only closes after displaying the splash screen for some time when an invalid SIM is detected or no data connection is present.
However, I am looking to immediately close the app upon clicking the icon if an invalid SIM card is present or if no data connection is available. Where should I insert the code snippet provided in order to achieve this desired functionality? Or is there another approach that could be used instead? Any assistance with this matter would be greatly appreciated.