码迷,mamicode.com
首页 > 移动开发 > 详细

Mac iOS-----PhoneGap 添加条形扫描码插件

时间:2015-04-24 12:16:06      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

此随笔记录的是通过plugman来安装phonegap插件。

 

第1步:安装plugman

npm install -g plugman

QiaodeMacBook-Pro:MyApp root# npm install -g plugman
npm WARN engine npm@1.3.4: wanted: {"node":">=0.6","npm":"1"} (current: {"node":"0.12.2","npm":"2.7.4"})
npm WARN installMany normalize-package-data was bundled with npm@1.3.4, but bundled package wasnt found in unpacked tree
npm WARN engine cordova-js@3.9.0: wanted: {"node":"~0.10.x"} (current: {"node":"0.12.2","npm":"2.7.4"})
npm WARN engine xmlbuilder@2.2.1: wanted: {"node":"0.8.x || 0.10.x"} (current: {"node":"0.12.2","npm":"2.7.4"})
/usr/local/node/bin/plugman -> /usr/local/node/lib/node_modules/plugman/main.js
plugman@0.23.1 /usr/local/node/lib/node_modules/plugman
├── underscore@1.7.0
├── q@1.0.1
├── nopt@1.0.9 (abbrev@1.0.5)
├── rc@0.5.2 (strip-json-comments@0.1.3, deep-extend@0.2.11, ini@1.1.0, minimist@0.0.10)
├── npm@1.3.4 (normalize-package-data@2.0.0)
└── cordova-lib@5.0.0 (valid-identifier@0.0.1, osenv@0.1.0, properties-parser@0.2.3, bplist-parser@0.0.6, mime@1.2.11, unorm@1.3.3, semver@2.1.0, shelljs@0.3.0, dep-graph@1.1.0, xcode@0.6.7, npmconf@0.1.16, through2@0.6.3, elementtree@0.1.5, glob@4.0.6, cordova-app-hello-world@3.9.0, tar@1.0.2, plist@1.1.0, cordova-registry-mapper@1.1.0, init-package-json@1.4.2, d8@0.4.4, request@2.47.0, cordova-js@3.9.0)

 

第2步:进入项目根目录下载插件

QiaodeMacBook-Pro:Desktop root# cd MyApp
QiaodeMacBook-Pro:MyApp root# git clone https://github.com/wildabeast/BarcodeScanner.git plugins/com.phonegap.plugins.barcodescanner
Cloning into plugins/com.phonegap.plugins.barcodescanner...
remote: Counting objects: 1735, done.
remote: Total 1735 (delta 0), reused 0 (delta 0), pack-reused 1735
Receiving objects: 100% (1735/1735), 3.87 MiB | 572.00 KiB/s, done.
Resolving deltas: 100% (515/515), done.
Checking connectivity... done.

 

第3步:开始安装

QiaodeMacBook-Pro:MyApp root# plugman install --plugins_dir plugins --plugin com.phonegap.plugins.barcodescanner --platform ios --project platforms/ios
Installing "com.phonegap.plugins.barcodescanner" for ios

 

第4步:测试

打开index.html,添加一个链接,并增加1个点击事件。代码如下:

<a class="button addBtn" id="BarcodeScanner">BarcodeScanner</a>


<script>
$("#BarcodeScanner").click(function(){
     cordova.plugins.barcodeScanner.scan(
             function(result) {
                 alert("Scanned Code: " + result.text + ". Format: " + result.format
                     + ". Cancelled: " + result.cancelled);  
             }, function(error) {  
                 alert("Scan failed: " + error);  
             });
 })
</script>    

 

PS:记的不要少了引入phonegap的js,否则调用不了

<script src="cordova.js"></script>

 

Mac iOS-----PhoneGap 添加条形扫描码插件

标签:

原文地址:http://www.cnblogs.com/fh2002/p/4452965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!