集成二維碼掃描插件
- 如何集成二維碼掃描插件
- 集成ngCordova官網(wǎng)教程直達(dá)鏈接
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`[官網(wǎng)直達(dá)鏈接](http://ngcordova.com/docs/plugins/barcodeScanner/)
cordova plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git
- 在controller中調(diào)用
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);
});
};
});
更詳細(xì)的用法請(qǐng)參考插件GitHub地址
二維碼掃描問(wèn)題總結(jié)及解決辦法
- 點(diǎn)擊掃描权旷,時(shí)不時(shí)的直接卡死在相機(jī)界面吁朦?
控制一下點(diǎn)擊打開(kāi)掃描的按鈕,不要被連擊就行了亦渗。如果連續(xù)調(diào)兩次就會(huì)卡死 - 同一個(gè)二維碼,安卓手機(jī)識(shí)別正常但是iOS死活識(shí)別不了?或者相反?糾結(jié)識(shí)別二維碼速度太慢套像?推薦嘗試一下下面這個(gè)二維碼掃描插件csZBar