Search code examples
ibm-mobilefirsthybrid-mobile-app

Worklight 6.1: How to add EULA to hybrid app


Environment: Worklight 6.1.0.2 dojo 1.9.4

We have created a hybrid app using Worklight 6.1 for android, iOS and windows8 platform. Now we would like to add and show End User License Agreement (EULA) window to the user, when the app first time launch. It should have Accept and Decline button. If user tap on Accept button, then he should be able to use the app. I would like to know, how can we achieve this using Worklight 6.1.

Any help on this, will be much appreciated.


Solution

  • FYI there is nothing specific here to Worklight.
    You could implement this in any number of ways w/out ever using any Worklight API whatsoever.

    You could achieve it for example like this (untested code - you'll need to experiment):

    1. In main.js create some global variable eulaAccepted:

      var eulaAccepted; // You will need to handle this property using HTML5 Local Storage so that it will persist for the next time the app is launched, and have the app act accordingly.

    2. Then, in wlCommonInit():

      function wlCommonInit() {
          if (!eulaAccepted) {
              displayEula();
          } else {
              displayApp();
          }
      }
      
    3. In displayEula():

      function displayEula() {
          // either display a dialog using `WL.SimpleDialog`...
          // Or maybe custom HTML with "accept" and "not accept" buttons
      
          WL.SimpleDialog.show(
              "Eula Agreement", "your-eula-text-here", 
              [{text: "Accept", handler: acceptEula },
              {text: "Reject", handler: rejectEula}]
          );
      }
      

      Handle the result:

      function acceptEula() {
          eulaAccepted = true;
          ... // Some code that will store the `eulaAccepted` variable using HTML5 Local Storage API
          displayApp();
      }
      
      function rejectEula() {
          // Display some other custom HTML instead of your app.
          // Maybe also additional logic to try again to accept the Eula...
      }