Shutting down Worklight application upon tapping using SIM card information

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.

Answer №1

wlCommonInit occurs once the app is up and running, following the loading of the Worklight and Cordova frameworks, making it an unsuitable location for your request.

As the app initializes, a splash screen appears...

Your proposed functionality seems flawed.
Having an app abruptly close without any notification could give the impression that the app crashed - resulting in negative feedback from users.

Why force the app to close?

  • Instead, initiate the app with connectOnStartup: false, preventing automatic connection to the Worklight Server upon launch. Check for network availability and inform the user accordingly - allowing them to decide whether to continue using the app or not.

If you still wish to exit the app at launch due to lack of network presence or undesired connectivity, this task should be handled in Native code.

For instance, in Android, refer to src\com ... yourApp.java, specifically near the onCreate method where native capabilities can be utilized to achieve this desired action.

  • To gain insights on implementing this in native code, a related question on a similar topic can be found here: IBM Worklight - Unable to get network signal strength in Android

If uniform implementation across various platforms within Worklight is required, separate execution in native code must be carried out for each platform, or... reconsider the current approach, or maintain the existing procedure.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to verify if the password entered by the user matches the input provided in the old password field?

I am trying to compare the user's password with the one entered in the "oldPassword" input field. The challenge is hashing the input from the "oldPassword" field for comparison. How can I achieve this? Please review my ejs file and suggest improvement ...

Having difficulty getting the forEach method to function correctly on Internet Explorer

I successfully implemented an active/disable feature in my code that functions flawlessly on both Chrome and Firefox. However, I am encountering an error in IE specifically when using the forEach method. Upon testing, the following error message appears w ...

"Troubleshooting: Vue ChartJS Line Chart fails to show data

Hey there! I'm currently working on integrating Chart.js with the vue-chartjs wrapper to build a Line Chart using data retrieved from my API. The data is being successfully logged to the console without any errors, but for some reason, the Line Chart ...

The problem with Vue JS static links

I'm currently working with a Vue.js application (v2). I've noticed that if I skip visiting the root of the site, the sub-links do not work properly. For example: Visit: Then go to If I directly visit: I encounter the following error messag ...

`Firefoxx border table glitch`

When attempting to open/close tables in Firefox using this link, unnecessary borders appear. https://i.sstatic.net/4tQCE.gif One way to fix this issue is by implementing the following JS solution: setTimeout(function () { $table.css({'table-la ...

Displaying a nested list of lists using AngularFire2 can be achieved by following these steps

I'm currently working on a task to showcase a list of 'stations' and underneath each 'station' returned, I want to display a list of 'projects' that are currently at that particular 'station'. By utilizing angul ...

The comparison between AJAX and JSON passing and PHP generating HTML versus returning it

Currently, my code looks like this: <li onclick = " function CBAppData( callerObj, data ) { var string = ''; for( a in data ) { debug.push( data[ ...

Angular factory variable scoping

I am encountering an issue with altering the folders variable (an array) within the return statement of my Angular factory. It seems to work for the create action, but I am having trouble with the scope of the variable in the factory. This code works: fo ...

How can I select a random object from a group of N items using Javascript?

We are discussing the use of CSS and Javascript in this project. I am looking to have 10 unique CSS div's appear randomly on the screen after a time delay of 1-3 seconds each. These div's will consist of a yellow square, green square, red square ...

Processing JSON data by reading multiple files using Node.js

I've encountered a situation where I have multiple files containing data with time stamps. It's important for me to read these files in order, line by line. However, I noticed that most Node packages utilize asynchronous methods for file reading. ...

When trying to install Firebase X in Ionic 5, CocoaPods encountered compatibility issues with the pod "Firebase/Performance"

Working on my project in Ionic 5 with Capacitor 2.1.2, I integrated Firebase X for Capacitor using the given code snippet. npm install cordova-plugin-firebasex npm install @ionic-native/firebase-x After running ionic cap sync, the android set up went smo ...

What is causing my HTML script tag to not recognize my JS file in Next.js?

Just starting out with Next.js and trying to access the web cam for a project I'm working on, but encountering an issue when writing in the "script" tag. Below is the simple code for page.js: export default function Live(){ return( <html> ...

Is there a way to conceal the parent div when all of its child divs are hidden?

I have a series of dynamically created divs set up like this: <div class='parent'> <div class='child'></div> <div class='child'></div> <div class='child'></div> < ...

Using Angular UI Router to Access $scope Beyond the Scope of the UI View

Looking for a way to access $scope outside the UI view in my todo app. The structure is simple, with three panels as shown in this design For the full code, visit here I need to access the to-do detail on the third panel using $rootScope, which currently ...

Update the ngView content on the fly

My project requires dynamic routes to be generated when specific URLs are requested in order to customize the view and display corresponding data uniformly. While adding manual routes with the same templateUrl and controller would have made this task simpl ...

Issue with passing incorrect props to child component occurs specifically on pages 2 and beyond within react-table

Implementing a button in each row of a table using react-table to trigger a react-modal is functioning correctly on the initial page. However, when navigating to subsequent pages, an issue arises where the incorrect id prop is being passed into the custom ...

Ways to retrieve form data following a post request using JavaScript

Does anyone know how to read form data from testPage.html in testPageResult.html? I have created a html page called testPage.html with a form that has a post action like the following: <h2>HTML Forms</h2> <form action="http://test.com/tes ...

Issue with the demo code for Vue Stripe Checkout

As I delve into the world of Vue-Stripe-Checkout, I encountered a snag right from the start with the demo code provided. The issue arises when utilizing the Vue Stripe Elements component. Has anyone else experienced this problem? There are no errors displa ...

Is there a distinction between assigning a property on app.locals versus invoking app.set()?

Currently, I am immersing myself in learning Express and pondering over the ideal place to store configuration data. One option is to utilize either app.locals or app.set (settings) for this purpose: app.locals({ config: { name: 'My App', ...

Transitioning the height of a Vue component when switching routes

I've been struggling to implement a transition slide effect on my hero section. The height of the hero is set to 100vh on the homepage and half of that on other pages. Despite trying various methods, I haven't been able to get it working properly ...