iOS中未调用cordova.exec
我不知道为什么,但是在我的本地代码中没有调用iOS中未调用cordova.exec,ios,cordova-3,Ios,Cordova 3,我不知道为什么,但是在我的本地代码中没有调用cordova.exec。有人能解决这个问题吗? config.xml <widget xmlns = "url" id = "io.cordova.helloCordova" version = "2.0.0"> <!-- <content src="url" /> for external pages --> <content src="index
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>
Myhybridge.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];
}
问题是调用了myhybridge.js
中的updateSlider
方法。在这里,我调用了cordova.exec
方法,因此应该调用myhybridge.m
中的ACTION\u SLIDER\u VALUE
方法。但是我不知道为什么没有调用它。有人能解决这个问题吗?
谢谢你不打电话是什么意思?你有js错误吗?-(void)ACTION\u SLIDER\u VALUE:(CDVInvokedUrlCommand*)命令`method未被调用。我没有收到任何错误,也没有在.m文件中调用该方法。你的插件是否在config.xml中注册?我已经更新了问题以供你验证。我是如何将其添加到config.xml的?这是否正确?
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");
}
-(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];
}