集成二维码扫描插件
- 如何集成二维码扫描插件
- 集成ngCordova官网教程直达链接
You can use bower to install ngCordova like so or download the zip file here, and locate the .js file in the dist folder:
$ bower install ngCordova
Include ng-cordova.js or ng-cordova.min.js in your index.html file before cordova.js and afteryour AngularJS / Ionic file (since ngCordova depends on AngularJS).
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
Inject as an Angular dependency
Then, include ngCordova as a dependency in your angular module:
angular.module('myApp', ['ngCordova'])
- 安装插件:`$cordovaBarcodeScanner`[官网直达链接](http://ngcordova.com/docs/plugins/barcodeScanner/)
cordova plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git
- 在controller中调用
angular.module('barcodescanner', [])
.controller('BarcodeScannerCtrl', function($scope,$state,$cordovaBarcodeScanner,MyAppUtils){
$scope.openScanCamara = function(){
$cordovaBarcodeScanner.scan()
.then(function(barcodeData) {
// Success! Barcode data is here
MyAppUtils.showCustomAlert(barcodeData.text);
}, function(error) {
// An error occurred
MyAppUtils.showCustomAlert(error);
});
};
});
更详细的用法请参考插件GitHub地址
二维码扫描问题总结及解决办法
- 点击扫描,时不时的直接卡死在相机界面?
控制一下点击打开扫描的按钮,不要被连击就行了。如果连续调两次就会卡死 - 同一个二维码,安卓手机识别正常但是iOS死活识别不了?或者相反?纠结识别二维码速度太慢?推荐尝试一下下面这个二维码扫描插件csZBar
网友评论