javascript Phonegap 3.0.0:BarcodeScanner 插件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18142247/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 10:51:47  来源:igfitidea点击:

Phonegap 3.0.0: BarcodeScanner Plugin

javascriptcordovaphonegap-pluginsbarcode-scanner

提问by user1448982

currently I'm trying to install the BarcodeScanner Pluginfor Phonegap Version 3.0.0. I can't find any working documentation on how to install it correctly and I didn't figure it out myself. So I would really appreciate any help!

目前我正在尝试安装BarcodeScanner Pluginfor Phonegap Version 3.0.0. 我找不到任何有关如何正确安装它的工作文档,而且我自己也没有弄清楚。所以我真的很感激任何帮助!

Thank you in advance! Best regards, Andreas

先感谢您!最好的问候, 安德烈亚斯

回答by Jonathan Naguin

Actually there are a couple of discussions about this issue on the github page of the plugin hereand here.

实际上,在此处此处的插件的 github 页面上有一些关于此问题的讨论。

I managed to have a version working in iOS and Android, you can check it here. There is another forkthat has made a pull request to the original with changes for 3.0.0 even I am not quite sure that the plugin works in iOS.

我设法有一个适用于 iOS 和 Android 的版本,你可以在这里查看。还有另一个fork向原始版本发出了拉取请求,并针对 3.0.0 进行了更改,即使我不太确定该插件在 iOS 中是否有效。

Instructions to install (Using cordova cli)

安装说明(使用cordova cli

  1. Download the repo using GIT or just a ZIP from Github.
  2. Add the plugin to your project (from the root of your project):

    cordova plugin add <path_download_plugin>

  3. You can start using plugins.barcodeScannerto invoke the plugin in your HTML/JS code.
  4. Do not forget to call cordova prepareto copy your files to each platform project.
  1. 使用 GIT 或仅从 Github 下载一个 ZIP 文件。
  2. 将插件添加到您的项目中(从项目的根目录):

    cordova plugin add <path_download_plugin>

  3. 您可以开始使用plugins.barcodeScanner在您的 HTML/JS 代码中调用插件。
  4. 不要忘记调用cordova prepare将您的文件复制到每个平台项目。

回答by Santosh Prasad Sah

Here is my explanation based on Jonathan solutions. I tried his solution and succeeded but took more time. So I thought to explain steps I followed so that it can save someone's time.

这是我基于 Jonathan 解决方案的解释。我尝试了他的解决方案并成功了,但需要更多时间。所以我想解释一下我遵循的步骤,这样可以节省别人的时间。

Steps:-

脚步:-

1) First install cordova if not already installed using Cordova cli as below

1) 如果尚未使用 Cordova cli 安装,请首先安装 Cordova,如下所示

Note: you must install node.jsif not already installed.

注意:如果尚未安装 node.js,则必须安装

npm install -g cordova
or
sudo npm install -g cordova

npm install -g cordova
或者
sudo npm install -g cordova

2) Go to the directory where you maintain your source code, and run a command such as the following:

2) 进入你维护源代码的目录,运行如下命令:

  • $ cordova create hello com.example.hello HelloWorld

    The first argument specifies a hello directory to be generated for your project. Its www subdirectory houses your application's home page, along with various resources under css, js, and img, which follow common web development file-naming conventions. The config.xml file contains important metadata needed to generate and distribute the application.

    The other two arguments are optional: the com.example.hello argument provides your project with a reverse domain-style identifier, and the HelloWorld provides the application's display text

  • $ cordova create hello com.example.hello HelloWorld

    第一个参数指定要为您的项目生成的 hello 目录。它的 www 子目录包含应用程序的主页,以及 css、js 和 img 下的各种资源,这些资源遵循常见的 Web 开发文件命名约定。config.xml 文件包含生成和分发应用程序所需的重要元数据。

    其他两个参数是可选的: com.example.hello 参数为您的项目提供反向域样式标识符,HelloWorld 提供应用程序的显示文本

  • cd hello
  • cd hello
  • cordova platform add ios
  • cordova platform add ios
  • cordova plugin add https://github.com/jonathannaguin/BarcodeScanner.git
  • cordova plugin add https://github.com/jonathannaguin/BarcodeScanner.git
  • cordova build
  • cordova build
  • cordova prepare

    3) remove all files from www folder except following

  • cordova prepare

    3) 从 www 文件夹中删除所有文件,除了以下文件

  • confix.xml
  • 配置文件
  • cordova_plugins.js
  • cordova_plugins.js
  • cordova.js
  • 科尔多瓦.js
  • plugins (folder contaning barcodescanner.js)

    and your own index.html,js,css files

    I will be glad if it helps someone.

  • 插件(包含barcodescanner.js 的文件夹)

    和你自己的 index.html,js,css 文件

    如果对某人有帮助,我会很高兴。

  • 回答by user10078

    i had the same error as @aruballo. To fix it i dropped the 3 the files from projectdir/Plugins/com.phonegap.plugins.barcodescanner/ inside the plugin directory in xcode.

    我和@aruballo 有同样的错误。为了修复它,我将 projectdir/Plugins/com.phonegap.plugins.barcodescanner/ 中的 3 个文件放在 xcode 的插件目录中。

    I also add one last problem with ARC restriction which was fixed by the answer from https://github.com/wildabeast/BarcodeScanner/issues/37#issuecomment-23320333(must add -fno-objc-arc in Project - Buil Phases - compile source - CDVBarcodeScanner.mm line to resolve the problem / double click that line and add "-fno-objc-arc")

    我还添加了 ARC 限制的最后一个问题,该问题已通过https://github.com/wildabeast/BarcodeScanner/issues/37#issuecomment-23320333的答案修复 (必须在 Project - Buil Phases 中添加 -fno-objc-arc -编译源 - CDVBarcodeScanner.mm 行来解决问题/双击该行并添加“-fno-objc-arc”)

    enter image description hereenter image description here

    在此处输入图片说明在此处输入图片说明

    回答by aruballo

    @Jonathan Naguin: I tried to follow your instructions, but I am receiving the following:

    @Jonathan Naguin:我尝试按照您的指示进行操作,但收到以下信息:

    2013-08-09 17:58:57.416 PUIClient[3160:907] CDVPlugin class CDVBarcodeScanner (pluginName: BarcodeScanner) does not exist. 2013-08-09 17:58:57.419 PUIClient[3160:907] ERROR: Plugin 'BarcodeScanner' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.

    2013-08-09 17:58:57.416 PUIClient[3160:907] CDVPlugin 类 CDVBarcodeScanner (pluginName: BarcodeScanner) 不存在。2013-08-09 17:58:57.419 PUIClient[3160:907] 错误:找不到插件“BarcodeScanner”,或者不是 CDVPlugin。检查 config.xml 中的插件映射。

    The plugin seemed to install well enough, but when I try calling it in my application I receive this error. Any idea whats going on? I tried to reply to your answer but stackoverflow deems it neccessary for me to have 50 reputation. Thanks for all your help!

    该插件似乎安装得很好,但是当我尝试在我的应用程序中调用它时,我收到了这个错误。知道发生了什么吗?我试图回复您的回答,但 stackoverflow 认为我有必要拥有 50 声望。感谢你的帮助!

    回答by MugosDynamic

    i think,the documentation has a mistake.

    我认为,文档有错误。

    Change the "Class' from NSObject to PGbcsViewController

    将“类”从 NSObject 更改为 PGbcsViewController

    After you add the .h,.cpp and .mm files to the project; if you search for 'PGbcsViewController' ,you can't find anything . (at least mine version of barcode plugin.) I corrected it as 'CDVbcsViewController' and i am using barcode scanner plugin without problem at ios,too.

    将 .h、.cpp 和 .mm 文件添加到项目后;如果您搜索 'PGbcsViewController' ,则找不到任何内容。(至少是我的条形码插件版本。)我将其更正为“CDVbcsViewController”,并且我在 ios 上使用条形码扫描仪插件也没有问题。

    So parent class of view is important. You should check that.

    所以父类的视图很重要。你应该检查一下。