美文网首页
Ionic ngCordova插件篇-二维码扫描

Ionic ngCordova插件篇-二维码扫描

作者: BlessNeo | 来源:发表于2016-06-24 09:53 被阅读5008次

    集成二维码扫描插件

    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

    相关文章

      网友评论

          本文标题:Ionic ngCordova插件篇-二维码扫描

          本文链接:https://www.haomeiwen.com/subject/lyeodttx.html