I am trying to call javascript function from native plugin in cordova iOS 4.0.0. In the previous cordova ios version 3.9.2, I can call any javascript function from native plugin like this.
- (void)PlayMp3:(CDVInvokedUrlCommand*)command
{
NSString* callbackId = [command callbackId];
NSString* name = [[command arguments] objectAtIndex:0];
NSString* msg = [NSString stringWithFormat: @"Hello, %@", name];
CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsString:msg];
MainViewController* viewController = (MainViewController*)self.viewController;
NSString *jsCallBack = [NSString stringWithFormat:@"setPlayStatus();"];
[viewController.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
[self success:result callbackId:callbackId];
}
But in Cordova iOS 4.0.0, I can't call javascript function setPlayStatus() like as above. Because viewController.webview is not UIWebView type. It is UIView. So I was tried to like this.
- (void)PlayMp3:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
NSString* echo = [command.arguments objectAtIndex:0];
if (echo != nil && [echo length] > 0) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
WKWebView* webview = (WKWebView*)self.viewController.view;
NSString *jsCallBack = [NSString stringWithFormat:@"setPlayStatus();"];
[webview evaluateJavaScript:@"setPlayStatus();" completionHandler:nil];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
But it didn't work. How can I call javascript function in native cordova plugin in Cordova Plugin iOS 4.0.0?
evaluateJavaScript?