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