Ionic 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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容