迁移cordova项目时找不到插件

时间:2015-08-10 13:42:45

标签: cordova cordova-plugins

我正在将应用从Cordova 2.2.0迁移到3.5。我正在使用iOS的自定义插件,负责扫描条形码。我已将代码放在Cordova Library项目下的文件夹中。

我使用以下代码调用插件:

var RedLaserPlugin = {
scanBarcode: function(successFunction, failFunction) {
  return Cordova.exec(successFunction, failFunction, "RedLaserPlugin",
                      "scanBarcode", []);
}

}

和...在加载应用时,

document.addEventListener("deviceready", function () { Cordova.exec(rlp_success, rlp_failure, "RedLaserPlugin", "init", []); }, false);

在config.xml文件中我已使用...

添加了插件的依赖项
<feature name="RedLaserPlugin">
    <param name="ios-package" value="RedLaserPlugin" />

但是当我运行应用程序时,它无法将插件绑定到xcode项目并提供以下内容:

-[CDVCommandQueue executePending] [Line 159] FAILED pluginJSON = ["RedLaserPlugin1615451183","RedLaserPlugin","init",[]]

尝试了多种组合以使其发挥作用,但没有一种能够发挥作用。我错过了什么吗?

编辑:我在下面的文件夹中创建了一个plugin.xml:

<js-module src="www/RedLaserPlugin.js" name="RedLaserPlugin">
<clobbers target="navigator.RedLaserPlugin" />

    = 3.8.0“/&gt;

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

<header-file src="platforms/ios/Production/Classes/MainViewController.h" />
<header-file src="platforms/ios/Production/Classes/MainViewController.m" />
<header-file src="platforms/ios/Production/Classes/MainViewController.xib" />
<header-file src="platforms/ios/Production/Classes/MainViewController.m" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPlugin.h" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPlugin.m" />
<header-file src="platforms/ios/Production/Plugins/RedLaserSDK.h" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPluginFiles/RedLaserOverlayController.h" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPluginFiles/RedLaserOverlayController.m" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPluginFiles/RedLaserOverlayController.xib" />

并尝试使用cmd

安装插件
cordova plugin add RedLaserPlugin.js

但它在终端中给出了错误,如:

TypeError: Cannot read property 'match' of undefined

2 个答案:

答案 0 :(得分:0)

我假设你从Cordova 3.5获得了一个新的Xcode项目。

如果这是正确的,您是否添加了要编译的插件来源?

转到Build Phases然后打开Compiled Sources下拉列表。单击+并添加应该已经在plugins目录中的缺少的插件源。

答案 1 :(得分:0)

我认为你的plugin.xml无效。

以下是我为自定义插件创建的示例plugin.xml模板:

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
    id="your_plugin_id"
    version="your_version">

    <name>plugin_name</name>
    <description>description</description>
    <license>Apache 2.0</license>
    <keywords>keyword_of_the_plugin</keywords>

    <!-- ios -->
    <platform name="ios">
      <source-file src="Plugin_source_file" />

      <framework src="required_framework" />

      <config-file target="config.xml" parent="/*/plugins">
          <feature name="feature_name">
              <param name="ios-package" value="plugin_name"/>
          </feature>
      </config-file>
      <config-file target="config.xml" parent="/*">
        <access origin="*" />
      </config-file>
    </platform>

    <!-- android -->
    <platform name="android">
        <!-- android-specific elements -->
    </platform>
</plugin>

例如,检查以下documentation