Search code examples
cordovamonacaonsen-ui2

Onsen 2 - Monaca CLI - Cordova plugins BarcodeScanner


I am creating a barcode scanner app with scandit scanner using Onsen 2 and Monaca . I integrate the scan library as plugin cordova plugin add . Everything works fine with Android and iPad but for iOS 10+, its showing a weird behaviour. The camera get open only after i press the home button of the phone and soon the resume the app to foreground, the scanner work fine.

I found a similar question already asked here, but there is no answer yet here. Onsen 2 - Monaca CLI - Cordova plugins weird behavior

Please reconsider my question before marking duplicate as the issue is still open.

Below is my code

scan() {
    
        console.log('............scan clicked...........');
        
    (<any>window).Scandit.License.setAppKey(“xxxxxxxxxxxxxxxxxxxxx”);
        var settings = new (<any>window).Scandit.ScanSettings();
        settings.setSymbologyEnabled((<any>window).Scandit.Barcode.Symbology.EAN13, true);
        settings.setSymbologyEnabled((<any>window).Scandit.Barcode.Symbology.UPC12, true);
        settings.setSymbologyEnabled((<any>window).Scandit.Barcode.Symbology.EAN8, true);
        var picker = new (<any>window).Scandit.BarcodePicker(settings);
        picker.show(success, null, failure);
    
        function success(session) {
            alert("Scanned " + session.newlyRecognizedCodes[0].symbology + " code: " + session.newlyRecognizedCodes[0].data);
    
    
            session.stopScanning();
    
        }
        function manual(content) {
    
            ons.notification.alert("Manual: " + content);
    
        }
        function failure(error) {
            ons.notification.alert("Failed: " + error);
    
        }
    
        picker.startScanning();
    
    
    }

Any help is appreciated Thank you


Solution

  • changing < meta > in "index.html"

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

    it work for me

    Thanks to Thumbal

    https://forum.ionicframework.com/t/cordova-inappbrowser-plugin-stopped-working-in-ios-10/64361/8