標籤:
此隨筆記錄的是通過plugman來安裝phonegap外掛程式。
第1步:安裝plugman
npm install -g plugman
QiaodeMacBook-Pro:MyApp root# npm install -g plugmannpm WARN engine [email protected]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 [email protected]1.3.4, but bundled package wasn‘t found in unpacked treenpm WARN engine [email protected]3.9.0: wanted: {"node":"~0.10.x"} (current: {"node":"0.12.2","npm":"2.7.4"})npm WARN engine [email protected]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[email protected]0.23.1 /usr/local/node/lib/node_modules/plugman├── [email protected]1.7.0├── [email protected]1.0.1├── [email protected]1.0.9 ([email protected]1.0.5)├── [email protected]0.5.2 ([email protected]0.1.3, [email protected]0.2.11, [email protected]1.1.0, [email protected]0.0.10)├── [email protected]1.3.4 ([email protected]2.0.0)└── cordova[email protected]5.0.0 ([email protected]0.0.1, [email protected]0.1.0, [email protected]0.2.3, [email protected]0.0.6, [email protected]1.2.11, [email protected]1.3.3, [email protected]2.1.0, [email protected]0.3.0, [email protected]1.1.0, [email protected]0.6.7, [email protected]0.1.16, [email protected]0.6.3, [email protected]0.1.5, [email protected]4.0.6, [email protected]3.9.0, [email protected]1.0.2, [email protected]1.1.0, [email protected]1.1.0, [email protected]1.4.2, [email protected]0.4.4, [email protected]2.47.0, [email protected]3.9.0)
第2步:進入項目根目錄下載外掛程式
QiaodeMacBook-Pro:Desktop root# cd MyAppQiaodeMacBook-Pro:MyApp root# git clone https://github.com/wildabeast/BarcodeScanner.git plugins/com.phonegap.plugins.barcodescannerCloning into ‘plugins/com.phonegap.plugins.barcodescanner‘...remote: Counting objects: 1735, done.remote: Total 1735 (delta 0), reused 0 (delta 0), pack-reused 1735Receiving 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/iosInstalling "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 添加條形掃描碼外掛程式