The QR Scanner seems to be working in the background but doesn’t display a preview when calling show().
The code for the QR Scanner is a copy/paste from the example in the docs.
When moving the phone around over a QR code I will eventually get the following message in the console ( ‘qrcodetext’ is correct).
Both changes override the styling from the default Ionic style sheet. Without the changes, the camera preview runs underneath the app and isn’t visible.
you saved my god damn booty! this nav-decor appeared for me when i used ion-tabs. Before i used them, the qr-scanner just worked like @markmccarthy described.
thanks for your solution which works correctly in ionic 4.
However window.document.body.style.backgroundColor = '#FFF'
seems like not doing their job.
After qr code scanner is activated and destroyed, dragging of ion-refresher will show gray/transparent background color instead of white. Anyone can help with this?
I’m using react with Ionic 5 and this is working (I have to put the show() call):
const qrScanner: QRScanner = new QRScanner();
const preview = (show: boolean): void => {
if (show) {
(window.document.querySelector("ion-app") as HTMLElement).classList.add("cameraView");
window.document.body.style.backgroundColor = "transparent";
} else {
(window.document.querySelector("ion-app") as HTMLElement).classList.remove("cameraView");
window.document.body.style.backgroundColor = '#FFF';
}
}
qrScanner.prepare()
.then((status: QRScannerStatus) => {
if (status.authorized) {
preview(true);
// camera permission was granted
qrScanner.show();
// start scanning
let scanSub = qrScanner.scan().subscribe((text: string) => {
preview(false);
console.log("Scanned something", text);
qrScanner.hide(); // hide camera preview
scanSub.unsubscribe(); // stop scanning
});
} else if (status.denied) {
// camera permission was permanently denied
// you must use QRScanner.openSettings() method to guide the user to the settings page
// then they can grant the permission from there
} else {
// permission was denied, but not permanently. You can ask for permission again at a later time.
}
})
.catch((e: any) => console.log("Error is", e));