0

I am trying to integrate iOS Native code to my Worklight application.

I Have created a Cordova plug-in with the below code:

HelloWorldPlugin.h

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

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

HelloWorldPlugin.m is

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

      CDVPluginResult *pluginResult=[CDVPluginResult 
        resultWithStatus:CDVCommandStatus_OK mes sageAsString:responseString];

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

       }

The above code is working. Next, I have created a BarcodeScannerViewController Class. It contains: BarcodeScannerViewController.h, BarcodeScannerViewController.m and BarcodeScannerViewController.xib.

I need to call the BarcodeViewController so that the functionality of barcode should happen.
In above HelloWorldPlugin.m I have modified code as below to move to BarcodeScannerViewController

        @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];
     }

But i am not able to move and getting log error as

  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
  • Are you trying to use a pre-existing Cordova Barcode scanner? Which? – Idan Adar Jul 11 '14 at 06:38
  • Thanks For Editing Idan – iOS devloper Jul 11 '14 at 06:39
  • No i have created my own code by using Apple framework .. – iOS devloper Jul 11 '14 at 06:40
  • And The class Which i have created is contains Buttons,outlets, textfields ...When i clicked the button scanning starts .But in HelloWorld Plugin only one method is there to call Back .my question is How to call My own class as same HelloWorld plugin Class is Called by Cordova Library ...Thanks For ur Help in Advance – iOS devloper Jul 11 '14 at 06:47
  • This cannot be debugged by talking. Provide your Worklight project and full native implementation files. Upload to dropbox. – Idan Adar Jul 11 '14 at 06:51
  • https://www.dropbox.com/s/js8l0abt31ldsup/TestApp.zip,https://www.dropbox.com/s/7m2t87ntvvwf4lq/BArcode%20files.zip these are my files please help – iOS devloper Jul 11 '14 at 10:35
  • Why did you not mention that you've edited helloworklight.m with your own code? why did you add cordovalib to the nativeresources folder? – Idan Adar Jul 11 '14 at 12:15
  • When building the project and opening it in Xcode, the barcodescanner files are not in the Classes folder. This despite having the xcodeproj file in nativeResources folder. It seems to me like you did not actually ADD the files in Xcode prior to copying the file to the nativeResources folder. I do not see this error in my Xcode console – Idan Adar Jul 11 '14 at 12:22
  • Thanks for ur help.. And i have edited by deleteing cordovalib in nativeresources folder. my code is working fine iam getting alertview – iOS devloper Jul 11 '14 at 12:50
  • Thanks for ur help.. And i have edited by deleting cordovalib in nativeresources folder. my code is working fine iam getting success alertview after running .now i do created code i.e helloworld.plugin calls the Barcode view controller. We should write any plug in inside BarViewController also? and iam getting these warnings in console log when code is runed on xcode – iOS devloper Jul 11 '14 at 13:07
  • 2014-07-11 18:34:19.700 HelloWorld[4554:60b] THREAD WARNING: ['HelloWorldPlugin'] took '1427.093994' ms. Plugin should use a background thread. – iOS devloper Jul 11 '14 at 13:09
  • This warning is not related. – Idan Adar Jul 11 '14 at 13:11
  • Thanks For ur Help..As i followed ur steps Iam getting the same out put But the image icon is a button When we clicked that the barcode functionality should happen .i.e The controller should move to next view controller(BarCodeViewController).........Thanks for ur help once again Idan – – iOS devloper Jul 11 '14 at 13:32
  • You can, but you need to know objective c. I can't help you with that. – Idan Adar Jul 12 '14 at 05:45
  • I would suggest you to use the following [method](http://stackoverflow.com/questions/9826792/how-to-invoke-objective-c-method-from-javascript-and-send-back-data-to-javascrip) to communicate between iOS and Webview ( java script ) and do what ever you want in iOS. Note if you are targeting the app for multiple platform it is not suggested way. – Bluewings Jul 12 '14 at 07:35
  • @iOSdevloper, have you managed to solve this? – Idan Adar Nov 22 '14 at 10:03

1 Answers1

0

One of the .zip files you've uploaded (in the comments) is no longer available, so I cannot test it myself, but my suggestion is to implement this with the Send Action feature available in Worklight 6.2.

This way the implementation is very clean and straight forward. The basic premise is:

  1. From the application's JavaScript you will invoke an "action"
  2. This action will basically be to display your View Controller
  3. When you're done, you return from your custom View Controller back to the Worklight-provided View Controller (the web app...)

You can read about Send Action as well as see an example implementation, here:

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89