首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >插件找不到,或者不是CDVPlugin。检查config.xml中的插件映射

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

Stack Overflow用户
提问于 2014-02-15 01:04:08
回答 2查看 28.8K关注 0票数 10

我已经为iOS在plugin.xml中声明了插件文件如下:

代码语言:javascript
代码运行次数:0
运行
复制
  <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应用程序调用了这个函数

代码语言:javascript
代码运行次数:0
运行
复制
showCatPictures: function(interval) {
  exec(null, null, 'CDVOP', 'showCatPictures', [interval]);   
},

我正在运行应用程序,它使用xcode中的这个插件来查看调试输出。当我调用showCatPictures函数时,我会得到这样的结果:

代码语言:javascript
代码运行次数:0
运行
复制
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。

代码语言:javascript
代码运行次数:0
运行
复制
#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的最上面部分:

代码语言:javascript
代码运行次数:0
运行
复制
#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调用它的方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-16 00:09:13

这里有一个小的不重要的细节,我忘了在问题中提到。这就是使用插件的示例应用程序中的www/config.xml的样子。你能发现这个问题吗?

代码语言:javascript
代码运行次数:0
运行
复制
<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房间里的好心人,他们帮助我调试这个问题。我希望这能帮上忙。

票数 30
EN

Stack Overflow用户

发布于 2019-06-26 07:53:14

在我的例子中,当我在ios中遇到同样的问题时,错误是插件的plugin.xml文件中的错误。

代码语言:javascript
代码运行次数:0
运行
复制
        <config-file target="config.xml" parent="/*">
            <feature name="UDPSender">
                <param name="ios-package" value="UDPSender"/>
            </feature>
        </config-file>

这个值与当前文件中的值不匹配,在快速文件中,类的开头是这样的。

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

在这里我们可以看到在plugin.xml值是UDPSender,但是在快速文件中是HWPUDPSender,这两者应该是相同的。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21792101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档