ios 未找到插件,或者不是 CDVPlugin。检查 config.xml 中的插件映射
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21792101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Plugin not found, or is not a CDVPlugin. Check your plugin mapping in config.xml
提问by Aras
I have declared my plugin file for iOS inside plugin.xml like so:
我已经在 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" />
In the plugin JavaScript file I have this function which I later call from the JavaScript app
在插件 JavaScript 文件中,我有这个函数,稍后我从 JavaScript 应用程序调用
showCatPictures: function(interval) {
exec(null, null, 'CDVOP', 'showCatPictures', [interval]);
},
I am running the app that uses this plugin from xcode to see the debug output. I get this when I call the showCatPictures
function:
我正在运行使用 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
]
]
I suspect this mayhave something to do with all the stuff I imported, so here is CDVOP.h
我怀疑这可能与我导入的所有内容有关,所以这里是 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
and this is the top part of CDVOP.m:
这是 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];
}
Any ideas why the plugin does not seem to be properly initialized and why cant I call its methods with exec
?
任何想法为什么插件似乎没有正确初始化以及为什么我不能用 调用它的方法exec
?
回答by Aras
Here is an small unimportant detail I forgot to mention in the question. This is what the www/config.xml
in the sample app using the plugin looked like. Can you spot the issue?
这是我在问题中忘记提及的一个不重要的小细节。这就是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>
Notice the space in the application name <name>My Cordova Test</name>
. This seems to work at first, but it puts spaces in the folder name that will later host your plugin. That is enough to interfere with the plugin installation process. This is what I did to fix the issue:
请注意应用程序名称中的空格<name>My Cordova Test</name>
。起初这似乎有效,但它会在文件夹名称中放置空格,稍后将托管您的插件。这足以干扰插件安装过程。这是我为解决问题所做的工作:
- changed the name of the test app to
MyCordovaTest
cordova platform remove ios
cordova plugin remove org.myplugin.cordova
cordova platform add ios
cordova plugin add ../my-plugin
cordova build ios
- 将测试应用程序的名称更改为
MyCordovaTest
cordova platform remove ios
cordova plugin remove org.myplugin.cordova
cordova platform add ios
cordova plugin add ../my-plugin
cordova build ios
Now the plugin is installed properly and is initialized as expected. Many thanks to the nice folks in #phonegap
IRC room who helped me debug this problem. I hope this helps someone.
现在插件已正确安装并按预期初始化。非常感谢#phonegap
IRC 房间里帮助我调试这个问题的好人。我希望这可以帮助别人。
回答by Awais Nasir
In my case, when I was facing the same issue in ios the error was that in plugin.xmlfile of plugin
就我而言,当我在 ios 中遇到同样的问题时,错误是在插件的plugin.xml文件中
<config-file target="config.xml" parent="/*">
<feature name="UDPSender">
<param name="ios-package" value="UDPSender"/>
</feature>
</config-file>
the value was mismatching with that of present in swift file, in swift file start of class was something like that
该值与 swift 文件中的值不匹配,在 swift 文件中,类的开头是这样的
@objc(HWPUDPSender) public class UDPSender: CDVPlugin, GCDAsyncUdpSocketDelegate{
@objc(HWPUDPSender) public class UDPSender: CDVPlugin, GCDAsyncUdpSocketDelegate{
here we can see in plugin.xmlvalue is UDPSenderbut in swift file it is HWPUDPSenderand these two should be same
在这里我们可以在plugin.xml中看到值是UDPSender但在 swift 文件中它是HWPUDPSender并且这两个应该是相同的