Ionic Qr扫描教程

时间:2017-08-14 15:16:08

标签: android cordova ionic-framework qr-code

我正在尝试使用phonegap-plugin-qrscanner扫描QR码。我按照教程步骤操作,但相机未在设备中打开。

这是我的代码:

constructor(private qrScanner: QRScanner) {}

this.qrScanner.prepare()
    .then((status: QRScannerStatus) => {
      console.log('QRScanStatus status:');
      console.log(status);
      if(status.authorized) {
               // start scanning
        let scanSub = this.qrScanner.scan().subscribe((text: string) => {
         console.log('Scanned something', text);

         this.qrScanner.hide(); // hide camera preview
         scanSub.unsubscribe(); // stop scanning
       });
        this.qrScanner.show();
      }else if(status.denied) {
        console.log('Status denied ...');
      }else{
        console.log('Otro estado ...');
      }
    })
    .catch((e) => {
      console.log('Error atrapado: ', e);
    });

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

似乎您正在尝试使用其他插件的API,即cordova-plugin-qrscanner

所以我的建议是将代码放在函数中并安装cordova-plugin-qrscanner

wrap_content

或者查看phonegap-plugin-barcodescanner的文档并相应地更改代码。