插件未找到,或者不是CDVPlugin。检查config.xml中的插件映射

时间:2014-02-15 01:04:09

标签: ios cordova phonegap-plugins cordova-plugins

我在plugin.xml中声明了我的iOS插件文件,如下所示:

  <config-file target="config.xml" parent="/*">
      <feature name="CDVOP">
          <param name="ios-package" value="CDVOP"/>
      </feature>
  </config-file>

  <header-file src="src/ios/CDVOP.h" />
  <source-file src="src/ios/CDVOP.m" />

在插件JavaScript文件中,我有这个函数,我稍后会从JavaScript应用程序调用

showCatPictures: function(interval) {
  exec(null, null, 'CDVOP', 'showCatPictures', [interval]);   
},

我正在运行从xcode使用此插件的应用程序来查看调试输出。当我调用showCatPictures函数时,我得到了这个:

OP Cordova Tests[1122:60b] ERROR: Plugin 'CDVOP' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-02-14 16:23:45.233 OP Cordova Tests[1122:60b] -[CDVCommandQueue executePending] [Line 127] FAILED pluginJSON = [
  "INVALID",
  "CDVOP",
  "showCatPictures",
  [
    30
  ]
]

我怀疑可能与我导入的所有内容有关,所以这里是CDVOP.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDV.h>
#import <Cordova/CDVViewController.h>

//OP SDK
#import "OpenpeerSDK/HOPStack.h"
#import "OpenpeerSDK/HOPLogger.h"
#import "OpenpeerSDK/HOPMediaEngine.h"
#import "OpenpeerSDK/HOPCache.h"
#import "OpenpeerSDK/HOPAccount.h"
#import "OpenpeerSDK/HOPIdentity.h"

@interface CDVOP : CDVPlugin <UIWebViewDelegate> {
    NSString* callbackId;
    UIImageView* peerImageView;
    UIImageView* selfImageView;
}

@property (nonatomic, copy) NSString* callbackId;
@property (retain, nonatomic) UIImageView *peerImageView;
@property (retain, nonatomic) UIImageView *selfImageView;

- (void) authorizeApp:(CDVInvokedUrlCommand*)command;
- (void) configureApp:(CDVInvokedUrlCommand*)command;
- (void) getAccountState:(CDVInvokedUrlCommand*)command;
- (void) startLoginProcess:(CDVInvokedUrlCommand*)command;
- (void) showCatPictures:(CDVInvokedUrlCommand*)command

@end

这是CDVOP.m的最重要部分:

#import "CDVOP.h"

@implementation CDVOP

@synthesize webView, selfImageView, peerImageView, callbackId;

-(CDVPlugin*) initWithWebView:(UIWebView*)theWebView
{
    self = (CDVOP*)[super initWithWebView:theWebView];
    NSLog(@">>> initializing with cordova webView <<<"); // actually this does not get called!
    return self;
}

// stress test UIImageViews using a series of cat pictures
- (void)showCatPictures:(CDVInvokedUrlCommand*)command
{   
    //initialize and configure the image view
    CGRect selfRect = CGRectMake(0, 0, 100.0, 200.0);
    self.selfImageView = [[UIImageView alloc] initWithFrame:selfRect];
    [self.webView.superview addSubview:self.selfImageView];

    // load pictures and start animating
    NSLog(@"displaying cat pictures");
    selfImageView.animationImages = [NSArray arrayWithObjects:
      [UIImage imageNamed:@"1.JPG"], [UIImage imageNamed:@"2.JPG"], [UIImage imageNamed:@"3.JPG"],
      [UIImage imageNamed:@"4.JPG"], [UIImage imageNamed:@"5.JPG"], [UIImage imageNamed:@"6.JPG"],
      [UIImage imageNamed:@"7.JPG"], [UIImage imageNamed:@"8.JPG"], nil];

    selfImageView.animationDuration = 0.3;
    [selfImageView startAnimating];
}

为什么插件似乎没有被正确初始化以及为什么我不能用exec调用它的方法?

2 个答案:

答案 0 :(得分:28)

这是我在问题中忘记提及的一个不重要的细节。这就是使用插件的示例应用程序中的www/config.xml。你能发现这个问题吗?

<widget id="org.sample.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>My Cordova Test</name>
    <description>
        A series of tests demonstrating the use of my cordova plugin
    </description>
    <author email="" href="">
        That would be me
    </author>
    <content src="index.html" />
    <access origin="*" />
</widget>

请注意应用程序名称<name>My Cordova Test</name>中的空格。这似乎最初起作用,但它在文件夹名称中放置空格,以后将托管您的插件。这足以干扰插件安装过程。这就是我为解决这个问题所做的工作:

  • 将测试应用的名称更改为MyCordovaTest
  • cordova platform remove ios
  • cordova plugin remove org.myplugin.cordova
  • cordova platform add ios
  • cordova plugin add ../my-plugin
  • cordova build ios

现在插件已正确安装并按预期初始化。非常感谢#phonegap IRC会议室中帮助我调试此问题的优秀人员。我希望这有助于某人。

答案 1 :(得分:0)

在我的情况下,当我在ios中遇到相同的问题时,错误是插件的 plugin.xml 文件

        <config-file target="config.xml" parent="/*">
            <feature name="UDPSender">
                <param name="ios-package" value="UDPSender"/>
            </feature>
        </config-file>

该值与swift文件中的值不匹配,在swift文件中,类的开头就是这样

@objc(HWPUDPSender) public class UDPSender: CDVPlugin, GCDAsyncUdpSocketDelegate{

在这里,我们在 plugin.xml 中看到的值是 UDPSender ,但是在swift文件中,它的值是 HWPUDPSender ,并且这两个应该相同