iOS上的Cordova 3.0:未调用插件方法

iOS上的Cordova 3.0:未调用插件方法,ios,plugins,cordova,native,Ios,Plugins,Cordova,Native,我正在尝试按照此处的指南进行操作: 尤其是这个 我完全遵循了所有的步骤,但不知怎么的,插件不起作用。当我尝试调用JavaScript部分时,没有执行本机echo方法 为了确保插件已加载,我实现了pluginInitialize方法。这个插件似乎加载得很好 日志记录输出: 2013-10-28 13:04:16.824 AirPrototype[2288:18e03] Multi-tasking -> Device: YES, App: YES 2013-10-28 13:04:16.8

我正在尝试按照此处的指南进行操作:

尤其是这个

我完全遵循了所有的步骤,但不知怎么的,插件不起作用。当我尝试调用JavaScript部分时,没有执行本机echo方法

为了确保插件已加载,我实现了pluginInitialize方法。这个插件似乎加载得很好

日志记录输出:

2013-10-28 13:04:16.824 AirPrototype[2288:18e03] Multi-tasking -> Device: YES, App: YES
2013-10-28 13:04:16.840 AirPrototype[2288:18e03] Echo plugin init.
2013-10-28 13:04:16.841 AirPrototype[2288:18e03] [CDVTimer][echo] 0.748992ms
2013-10-28 13:04:16.841 AirPrototype[2288:18e03] [CDVTimer][TotalPluginStartup] 1.354039ms
实施:

#import "Echo.h"
#import "../Cordova/CDV.h"
#import "../Cordova/CDVPlugin.h"

@implementation Echo

- (void)echo:(CDVInvokedUrlCommand*)command
{

    CDVPluginResult* pluginResult = nil;
    NSString* echo = [command.arguments objectAtIndex:0];

    if (echo != nil && [echo length] > 0) {
        NSLog(@"echo called with arg %@",echo);
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];
    } else {
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
    }

    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)pluginInitialize
{
    NSLog(@"Echo plugin init.");
}


@end
我已将插件注册到:

<feature name="Echo">
    <param name="ios-package" value="Echo" />
    <param name="onload" value="true" />
</feature>
并使用

window.echo('echome', function(echoValue) {
    alert(echoValue == 'echome'); // should alert true.
});
但它不起作用

我只注意到Safari调试器抱怨:

加载资源失败:在此服务器上找不到请求的URL

找不到的URL似乎是文件://!gap_exec?1382961871341

有人已经有这个问题了吗?还是我做错了什么?我错过了什么

非常感谢您的任何建议

问候
MP

经过一些研究和代码挖掘,它似乎是一个Phonegap/Cordova bug

只有将CDVViewController作为子视图添加到常规UIViewController时,才会出现此问题

在这种情况下,类CDVURLProtocol的viewControllerForRequest方法无法找到正确的ViewController类。我只是做了一个快速的黑客攻击,并返回我唯一的CDVViewController在任何情况下


也许我会修复它,稍后提交补丁。

在调用插件之前是否等待调用onDeviceReady?是的。我正在收听事件,它被正确地触发了。谢谢老兄。在挖掘代码2天后。最后我找到了这个线程,而不是添加推送视图,它工作了。这仍然是一个问题吗?看起来我遇到了同样的问题。如果查看
viewControllerForRequest
,它将在整个应用程序生命周期中永远不会返回有效的viewController。它还拒绝在
gRegisteredControllers
中查找控制器。
window.echo('echome', function(echoValue) {
    alert(echoValue == 'echome'); // should alert true.
});