ramiromd
ramiromd

Reputation: 2029

Ionic Qr scan tutorial

I am trying to scan a QR code using phonegap-plugin-qrscanner. I follow the tutorial steps but, the camera is not open in the device.

It is my code:

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);
    });

Any ideas ?

Upvotes: 0

Views: 1080

Answers (1)

robbannn
robbannn

Reputation: 5013

Seems you are trying to use the API of another plugin, namely cordova-plugin-qrscanner

So my suggestion is to either, place your code in a function and install cordova-plugin-qrscanner:

$ ionic cordova plugin add cordova-plugin-qrscanner
$ npm install --save @ionic-native/qr-scanner

or take a look at the documentation for phonegap-plugin-barcodescanner and change you code accordingly.

Upvotes: 1

Related Questions