我不知道为什么但我的原生代码中没有调用cordova.exec
。有人可以解决这个问题吗?
config.xml中
<widget xmlns = "url"
id = "io.cordova.helloCordova"
version = "2.0.0">
<!-- <content src="url" /> for external pages -->
<content src="index.html" />
<feature name="MyHybridBridge">
<param name="ios-package" value="MyHybridBridge"/>
</feature>
<access origin="*"/>
</widget>
的index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="master.css" />
<title>Hello World</title>
<script>
function myFunction()
{
MyHybridBridge.updateSliderValue("Hello");
}
</script>
</head>
<body on
load="init();" id="stage" class="theme">
<p>Click the button to trigger a function.</p>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script type="text/javascript" src="cordova-2.1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>
<script type="text/javascript" charset="utf-8" src="MyHybridBridge.js"></script>
<script type="text/javascript" charset="utf-8" src="NativeEventsListener.js"></script>
</body>
</html>
MyHybridBridge.js
var MyHybridBridge = (function() {
var PLUGIN_NAME = "MyHybridBridge";
var ACTION_SLIDER_VALUE = "ACTION_SLIDER_VALUE";
this.updateSliderValue = function (value) {
alert("s");
cordova.exec(saySuccess, sayFailure, PLUGIN_NAME, ACTION_SLIDER_VALUE, [value]);
};
return this;
}());
function saySuccess() {
alert("Success");
}
function sayFailure () {
alert ("Failure");
}
MyHybridBridge.m
-(void)ACTION_SLIDER_VALUE:(CDVInvokedUrlCommand*)command{
NSLog(@"ACTION_SLIDER_VALUE");
CDVPluginResult *pluginResult;
if (command.arguments.count == 1){
NSString *title = [command.arguments objectAtIndex:0];
if ([title isKindOfClass:[NSNull class]]) title = nil;
ViewController *viewController = (ViewController*)self.viewController;
[viewController updateContent:title];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}
else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invalid number of parameters"];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
问题是调用了updateSlider
中的MyHybridBridge.js
方法。我在这里调用cordova.exec
方法,以便调用ACTION_SLIDER_VALUE
中的MyHybridBridge.m
方法。但我不知道为什么但是没有被调用。可以有人找出问题吗?
感谢