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

The validation for decimal numbers fails to function when considering the length

I've been struggling to come up with a regular expression for validating decimal numbers of a specific length. So far, I've tried using pattern="[0-9]){1,2}(\.){1}([0-9]){2}", but this only works for numbers like 12.12. What I'm aimin ...

Creating a simple form page using Express JS

I am a beginner in the world of Node Js and Express Js, currently diving into learning from a book titled "Jump Start NodeJs" by Sitepoint. The author has provided a simple Login Form page as an example in the book. However, when trying to implement the co ...

Dropzone.js only allows one audio file and one image thumbnail file to be uploaded simultaneously

Is there a way to limit the types of files that can be uploaded through Dropzone.js? Specifically, I want to restrict users to uploading only one image and one audio file. ...

Verification of Phone Numbers (Global)

I am attempting to create a validation check for mobile numbers, similar to the one implemented by Gmail. Check out Gmail's signup page here However, there is significant variation in phone number formats across different countries, making it challe ...

remove a section from the main body

body { display: flex; justify-content: center; align-items: center; background: #0e1538; } <canvas id="spaceholder" width="804" height="604"></canvas> </div> <div class="MenĂ¼Center"> <canvas id="canvas" width="800" ...

Change numbers into a comma-separated style containing two decimal points using javascript

I have been working on a JavaScript function to convert numbers into a comma-separated format with two decimal places: Here is my current code snippet: Number(parseFloat(n).toFixed(2)).toLocaleString('en'); The issue with this code is that it ...

"The file upload function is populating the req.body object, but not the req.file

I successfully implemented a file upload API using multer and express, which functions well when accessed through POSTMAN. However, I encountered an issue when trying to utilize the same API with another file upload API: The code I used can be found below ...

Struggling to synchronize the newly updated Products List array in zustand?

Let me clarify the scenario I am dealing with so you can grasp it better. I have a Cart and various Products. When a user adds the product (product_id = 1) twice to the cart with the same options (red, xl), I increase the quantity of that item. However, i ...

Sequelize is unable to retrieve a table from the database

I am configuring Sequelize in order to streamline the manipulation of an MSSQL database. My attempt to define a table called 'Stock' has resulted in unexpected behavior when trying to query it. Below is the code snippet I used for defining the t ...

having trouble compiling a react js file with webpack

One of my files, app.js, contains the following code snippet: handlePageClick = (data) => { let selected = data.selected; let offset = Math.ceil(selected * this.props.perPage); this.setState({offset: offset}, () => { this.setStat ...

Transferring data between modules in nodejs

Within my custom module, there is a method designed to query the database and check if a given username exists. I need certain values to be returned in order to determine the query result at a higher level. var findUserbyUsername=function(username) { ...

Discover the ins and outs of integrating YAML front matter into your destination directory path

I am looking to customize the path of my blog posts to include a fancy date format like /blog/2013/09/17 so that the links from my previous octopress blog remain intact. Within the YAML front matter on each markdown page, I have included the date informat ...

custom dialog box appears using ajax after successful action

Recently, I created a custom dialog/modal box with the following code: <div id="customdialog" class="modal"> <div class="modal__overlay"></div> <div class="modal__content"> <h2><strong>Hello</strong&g ...

What is the best way to test a route using nock and request-promise when the URL includes single quotes?

Trying to test an API call using nock + request-promise is resulting in an error due to mismatched routes caused by single quotes in the API's url. The problem arises from request-promise url encoding the quotes while Nock does not. You can view the ...

The function _plugins_vuetify__WEBPACK_IMPORTED_MODULE_136__.default is not usable as a constructor

I have created a Vue application using vue cli 3 and incorporated Vuetify. To optimize the size of my bundle, I decided to modify the way Vuetify is imported: The versions I am working with are vuetify 1.5.5 and vue 3.7.0 import Vue from 'vue'; ...

The form control is missing a specified name attribute, causing an error with the value accessor

<input type="email" class="form-control passname" [(ngModel)]="emailID" name="Passenger Email ID" placeholder="email" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$"/> <div class="shake-tool ...

Having trouble retrieving the value from the input field with Angular.js

I am having trouble retrieving the value from an input field using Angular.js. Below is the code explanation. Here is my controller code: $scope.shipping=0; $scope.addProductInfoData=function(billdata){ console.log('valid',$scope.shippi ...

Instead of using a computed getter/setter, make use of mapState and mapMutations to simplify

Currently, I am syncing a computed value to a component and using a computed setter when it syncs back from the component. I'm wondering if there is a more concise way to replace a computed getter/setter with mapState and mapMutations. How can this b ...

Assign a value to the input field based on changes made in another input field

I am brand new to the world of JavaScript and currently grappling with setting a value in an input field based on the onchange event of another input field. Here is my code sample for input field 1: <input type='text' onchange='methodTh ...

Displaying pictures under specific conditions

I've recently completed the coding and CSS for my website after working on it for quite some time. Now, I want to enhance it by incorporating new features. The website is fully operational and generates revenue primarily through Google AdSense. I am i ...