phonegap / phonegap-plugin-barcodescanner

cross-platform BarcodeScanner for Cordova / PhoneGap
MIT License
1.27k stars 1.41k forks source link

Barcode scanner not loading in iOS after granting camera access #490

Open pbergner opened 7 years ago

pbergner commented 7 years ago

Expected Behaviour

Actual Behaviour

Steps to Reproduce

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

iOS only

Cordova CLI version and cordova platform version

cordova --version - 4.3
cordova platforms - iOS only issue

Plugin version

6.0.5

Sample Code that illustrates the problem

I don't believe this illustrates the problem but here's how I'm opening the scanner. In the failing scenario described above the callbacks are never fired. It appears that the callbacks aren't fired in the Obj. C code either:

const scannerOpts = {
                    preferFrontCamera: false, // iOS and Android 
                    showFlipCameraButton: false, // iOS and Android 
                    showTorchButton: true, // iOS and Android 
                    torchOn: false, // Android, launch with the torch switched on (if available) 
                    prompt: "Place a barcode inside the scan area", // Android 
                    resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500 
                    //formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED 
                    //orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device 
                    disableAnimations: true, // iOS 
                    disableSuccessBeep: false // iOS 
                };

                cordova.plugins.barcodeScanner.scan(
                    function(scanResult) {
                        debugger;
                        resolve(scanResult);
                    },
                    function(scanError) {
                        debugger;
                        reject(scanError);
                    },
                    scannerOpts
                );

Logs taken while reproducing problem

I don't know Objective C but I didn't see any relevant logs

macdonst commented 7 years ago

@pbergner I gave this a try today and I could not reproduce the problem. The permission dialog overlays the barcode scanner for me then once I accept I can scan barcodes. Can you give us some more details on how to reproduce?

jcesarmobile commented 7 years ago

Looks like this one you closed as can not reproduce https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/327

I couldn't reproduce neither, for me it works as @macdonst said, the permission already overlays the scanner.

Are you using WKWebView plugin?

pbergner commented 7 years ago

@jcesarmobile Yes, I believe I am using WKWebView. I was able to workaround the issue by using the cordova diagnostic plugin to request camera authorization and then launch the scanner in the callback.

LioH commented 6 years ago

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

It is a permission issue.

bfabbri commented 4 years ago

Hey @LioH I was facing a weird problem with the camera opening and your solution fixed it too!

Just for you guys to know: on iOS the camera was opening only after one of these three situations: 1 - the app goes to background and then goes back to foreground 2 - I open and close the notification center (swipe down from the top of the screen) 3 - I open and close the control center (swipe up from the bottom of the screen)

It doesn't sounds like a permission issue, but for some reason the "gap://ready file:;" part of the meta solved it.