I have used QRScanner to scan QR codes.
I decided to use QRScanner instead of BarcodeScanner because with the first one I can create my own design:
Docs says that scan
method return and observable
that emits
the scanned text.
I have the next code to scan:
const scanSub = qrScanner.scan().subscribe((text: string) => {
console.log('Scanned something', text);
const slices = text.split('@');
if (slices.length !== 3) {
this._showToast({
message: 'No es un código de seguridad válido',
position: 'middle'
});
} else {
viewCtrl.dismiss({
code: slices[1]
});
qrScanner.hide();
scanSub.unsubscribe();
this._displayQRScanner(false);
}
});
qrScanner.show();
That’s because I’m looking for a string like 0.234283489283412@somethingImportant@0.23482394273422342
where I need to retrieve whatever is between @
sign. If it has not two @
signs it is an invalid string and scan until a valid one, otherwise I close the modal returning somethingImportant
and unsubscribe for scanning. But it just scan once