集成二維碼掃描插件
- 如何集成二維碼掃描插件
- 集成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