标签:
一、简介
开源软件 https://github.com/phonegap/phonegap-plugin-barcodescanner 可以支持各种类型的扫描,包括二维码等等……
QR Code
Data Matrix
UPC E
UPC A
EAN 8
EAN 13
Code 128
Code 39
ITF
插件内部使用类库 https://github.com/zxing/zxing
二、安装插件
首先准备项目:
ionic start IonicProject blank
cd IonicProject
ionic platform add android
ionic platform add ios
1、安装插件
This requires phonegap 5.0+ ( current stable v3.0.0 )
phonegap plugin add phonegap-plugin-barcodescanner
Older versions of phonegap can still install via the deprecated id ( stale v2.0.1 )
phonegap plugin add com.phonegap.plugins.barcodescanner
It is also possible to install via repo url directly ( unstable )
phonegap plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git
2、下载 ng-cordova 相应 js
下载 https://github.com/driftyco/ng-cordova/releases
将其中的 ng-cordova.min.js 拷贝到项目的 www/js 目录
修改 index.html 代码
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
三、使用类库
1、修改 app.js
angular.module(‘starter‘, [‘ionic‘, ‘ngCordova‘])
2、使用扫描功能
exampleApp.controller("ExampleController", function($scope, $cordovaBarcodeScanner) {
$scope.scanBarcode = function() {
$cordovaBarcodeScanner.scan().then(function(imageData) {
alert(imageData.text);
console.log("Barcode Format -> " + imageData.format);
console.log("Cancelled -> " + imageData.cancelled);
}, function(error) {
console.log("An error happened -> " + error);
});
};
});
标签:
原文地址:http://www.cnblogs.com/hugofgh/p/5053478.html