Я пытаюсь вызвать javascript из Native target-c, используя плагин cordova, но функция не вызывается.
Я пытался использовать: defineJavaScript из webViewEngine и evalJs из commandDelegate.
DetailViewController.h
@interface DetailViewController : CDVViewController
- (void) echo:(CDVInvokedUrlCommand *)command;
@end
@interface MainCommandDelegate : CDVCommandDelegateImpl
- (void) echo:(CDVInvokedUrlCommand *)command;
@end
@interface MainCommandQueue : CDVCommandQueue
- (void) echo:(CDVInvokedUrlCommand *)command;
@end
DetailViewController.m
- (void) viewDidLoad {
[super viewDidLoad];
self.view.frame = CGRectMake(0, 0, 320, 480);
[self.webViewEngine evaluateJavaScript:@"echoWithParam()" completionHandler:^(id Result, NSError * error) {
NSLog(@"** Error -> %@", error);
NSLog(@"** Sucess -> %@", Result);
}];
//[self.commandDelegate evalJs:@"echoWithParam()" scheduledOnRunLoop:NO];
}
Вход
** Ошибка -> (ноль)
** Успех ->
NativeBridge.js
cordova.define("native-bridge.NativeBridge", function(require, exports, module) {
var exec = require('cordova/exec');
var NativeBridge = {
echoWithParam: function() {
alert("called "+"echoWithParam");
}
}
module.exports = NativeBridge;
});
config.xml
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<plugin name="native-bridge" spec="https://github.com/gubd85/cordova-plugin.git" />
<engine name="ios" spec="^4.5.5" />