Search code examples
javascriptioscordovacamerabarcode-scanner

GMV Barcode scanner on IOS - Camera screen is not immediately displayed


i have a cordova application with cordova-gmv-barcode-scanner plugin installed. On Android, everything works fine, but there is a weird bug on when i run it on IOS.

What I am expecting ?

After users clicks on a button, i call GMVBarcodeScanner.scan(..) and expect that camera window pops up

What is happening ?

After user clicks on a button, i call MVBarcodeScanner.scan(..) and nothing happens. However, when i slide down just a little bit from top menu (just make interaction with top menu where battery indicator is), camera windows pops up and everything works as expected.

What ive tried ?

Ive tested on emulators with iphone 11, iphone 8, ipad 7 and also on real device (iphone 7). Behaviour is exactly the same an all devices either emulated or real.

Ive tried playing with deviceready event. But nothing helped. Event is fired as expected just after the click but camera appears only if i interact with top menu.

Ive tried running digest cycle (i use angularjs) after calling the function from event handler but had no effect

my JS

 $this.scanQrCode = function () {
    document.addEventListener("deviceready", function () {
        $window.plugins.GMVBarcodeScanner.scan({}, function (err, result) {

            if (err) {
                setRouteId(null);
                AppService.showAlert('No valid QR code.');
                return;
            }

            AppService.showMessage('Route was scanned.');
            var routeId = result.split(',')[0];
            var fqdn = result.split(',')[1];
            setRouteId(routeId, fqdn);

        });
    });
};

Any help would be greatly appreciated. I am running out of ideas.


Solution

  • I managed to solve my problem by allowing gap://ready in CSP META tag. Cordova tried to poke native api but couldnt as it was always blocked by security policy.

    Ive changed

    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />
    

    to

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' gap://ready file://* *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />