Leverage IBM Worklight to initiate iOS native code execution upon plugin creation

Currently, I am working on integrating iOS Native code into my Worklight application.

I have successfully developed a Cordova plug-in with the following code:

HelloWorldPlugin.h

#import <Foundation/Foundation.h>
#import <Cordova/CDV.h;

@interface HelloWorldPlugin : CDVPlugin {
    UINavigationController *navi;
}
-(void)sayHello:(CDVInvokedUrlCommand*)command;

The implementation in HelloWorldPlugin.m is as follows:

-(void)sayHello:(CDVInvokedUrlCommand *)command {
    NSString *responseString = [NSString stringWithFormat:@"Hello........World %@", [command.arguments objectAtIndex:0]];

    CDVPluginResult *pluginResult = [CDVPluginResult 
resultWithStatus:CDVCommandStatus_OK messageAsString:responseString];

    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

After successful implementation of the above code, I moved on to creating a BarcodeScannerViewController Class which consists of BarcodeScannerViewController.h, BarcodeScannerViewController.m, and BarcodeScannerViewController.xib files.

Next, I needed to call the BarcodeViewController for barcode functionality. In the modification made in HelloWorldPlugin.m below:

@implementation HelloWorldPlugin

-(void)sayHello:(CDVInvokedUrlCommand *)command {
    NSString *responseString = [NSString stringWithFormat:@"Hello........World %@", [command.arguments objectAtIndex:0]];

    CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:responseString];

    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    
    BarCodeScannerViewController *view = [[BarCodeScannerViewController alloc] init];
    
    navi = [[UINavigationController alloc] initWithRootViewController:view];
}

However, upon trying to move forward, I encountered an error in the logs:

2014-07-11 10:06:23.660 HelloWorld[548:60b] THREAD WARNING: 
['HelloWorldPlugin'] took
'214928.292969' ms. Plugin should use a background thread.

2014-07-11 10:06:23.666 HelloWorld[548:4207] void SendDelegateMessage(NSInvocation):

delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:)
failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode

Answer №1

I noticed that one of the .zip files you uploaded (in the comments) is no longer accessible, preventing me from testing it myself. Nevertheless, I recommend implementing this using the Send Action feature available in Worklight 6.2.

This approach ensures a clean and straightforward implementation. The basic concept involves:

  1. Invoking an "action" from the application's JavaScript
  2. Displaying your View Controller through this action
  3. Returning from your custom View Controller to Worklight-provided View Controller (the web app...) upon completion

You can learn more about Send Action and find an example implementation at these resources:

  • Sending actions and data objects from JavaScript code to native code
  • Sending actions and data objects from native code to JavaScript code
  • Question with example code (JS to native)
  • Example project (native to JS)

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

Issue encountered in IE9 and IE10 when loading the angular library results in the "SCRIPT5007: Object expected" error for Angular JS

I am currently working on an AngularJS application that needs to be compatible with Firefox, IE 9, and IE 10. We are using the latest version of the AngularJS library (currently at 1.3.15). Our serverside is based on Java in the JavaEE platform, running on ...

Learn the secrets of displaying a pop-up alert message seamlessly without interrupting the page's rendering process. Additionally, discover how to effortlessly refresh a chart every

I need to display a pop-up if the value is less than 3. I have tried using the alert function, but it causes the page to not render. How can I show the pop-up without blocking the page and refresh the chart every 30 seconds? <script> ...

React maintains the state of just a single element within an array at a time

I'm faced with a roadblock while developing my covid19 application. The app should display a list of countries on the left side of the screen, allowing users to add any number of countries to the right side for more detailed covid data. I'm still ...

Can a software be created to capture search results from the internet?

Is it feasible to create a program that can extract online search results? I am specifically interested in retrieving data from Some of the data I need include application numbers, such as 9078871 and 10595401 Although there are CAPTCHAs present, I am w ...

ExpressJs does not support query parameters with the router.get method

I am currently working on developing an Express app. Here is the code snippet I am using: const express = require("express"); const router = express.Router(); router.get("/:id", ControllerHandler(UserController.getSingle, GetUserReque ...

Insert a new class within the container div

I am looking to insert a 'disabled' class within a parent div named 'anchorxx' The disabled class div can be located anywhere within the anchorXX divs Is it achievable using jquery? I am unsure how to approach this task. Appreciate y ...

PHP file upload error: Angular JS form submission issue

I am currently working on creating an upload method using Angular and PHP. Here is what I have come up with so far... HTML <form class="well" enctype="multipart/form-data"> <div class="form-group"> <label for ...

Transferring application configurations across modules

Questioning my current approach, I am developing a model & collection package (which exposes mongodb results as a model) and aiming for a modular structure. However, within the models, there are hardcoded settings like host, port, password, etc., which ...

Using Javascript to organize an array of objects based on a specific condition

Having an array of objects structured as follows: obj = [{'name': 'Tom', 'age': 17, 'gender': 'male', 'color':'red', 'position':3}, {'name': 'Sam', ...

I possess a pair of UI tabs. Whenever a button located outside the tab is clicked, I am required to activate a distinct tab

As a beginner in Javascript, I recently encountered an issue with a UI tab element that contains two tabs. My goal is to create a button that, when clicked, will scroll up and activate the second tab. <style> .tab-container { overflow-x: ...

Error in Mongoose validation: "Please provide a value for the 'first' field and the 'last' field."

Another user has previously posted a similar question, but I'm still struggling with my MongoDB website. I am working on a project to store names using mongoose. Here is the code for my routes and models: const router = require("express").Router(); c ...

Having difficulty accessing POST data through $.ajax request

I am currently working on a simple JavaScript code that is set up to send POST requests to my local server. The JavaScript and PHP files are both located on localhost, so I don't have to worry about any cross-site issues for now. Here is the JavaScrip ...

Implementing the OnClick method for the button component

After successfully creating a reusable button component, I now want to assign different onClick links to each Button component. How can I achieve this? import styled from 'styled-components' const Button = styled.button` background: #0070f3; ...

Undefined arguments are causing issues in the Local Directive Vuejs

I'm struggling to properly set up a directive in Vue.js by following an example I found online. <div id="hook-arguments-example" v-demo:foo.a.b="message"></div> Here's the directive within the main Vue App code: const app = new ...

How can I alter the icon's color?

Is it possible for the icon's color to change to red when the condition is greater than 0, and to gray when the condition is equal to zero? <TouchableOpacity onPress={() => { if (Object.values(selectedIt ...

Modifying a single route among several nested routes with specific names

My template includes various named, nested views: Template 1: <body> <div ui-view></div> </body> Template 2: <header></header> <div ui-view="left"></div> <div ui-view="canva ...

How to break down nested arrays into multiple arrays in Swift 4?

Using JSON parsing in my news API development brought about significant improvements. Here's how the JSON data structure is organized: > { "status": "ok", "source": "associated-press", "sortBy": "top", -"articles": [ -{ "author": "CHRISTINA A. CA ...

Converting Strings into Variable Names in Vue.js: A Step-by-Step Guide

Hi everyone, I was wondering if there's a way to convert a string into a variable name. For example, I want to convert "minXLabel" to minXLabel so that I can use it within span tags like this: <span>{{minXLabel}</span>. I current ...

Making If Statements Easier

Currently, I'm tackling an assignment that involves utilizing if statements and switch statements. Here is a snippet of code that I am working on: if (validateField(document.forms[0].name) == false) { isValid = false; } if (validateField(docume ...

What is the best way to enhance the class following this condition in JavaScript?

Initially, the original script worked perfectly with just one class being added: function check_btn_charge() { if (parseInt(jQuery(".total-change-price").text()) >= 0) { jQuery(".btn-action-save-charge"+"&nbsp;"+"btn-danger" ...