I am using the cordons barcode scanner plugin for my iOS mobile app for mobile devices. The problem that I encountered is the initial use of the scanner, if the user does not provide permission for the camera, he requests access to the camera (as expected). However, it does not raise the camera and does not make any callbacks. If you close the application and try again, it will work correctly, since it no longer requires a permission check.
I have no experience with Objective-C, but I tried to narrow the reason by using breakpoints in the following file:
https://github.com/phonegap/phonegap-plugin-barcodescanner/blob/master/src/ios/CDVBarcodeScanner.mm
LN511 - Adding a breakpoint here where a prompt appears asking for camera permission. If I accept permission while this breakpoint is active and resumes, everything works correctly and the camera’s user interface opens. If I instead continue to execute (it then calls scanBarcode()) until it finishes, and then accept a resolution that the camera did not open and callbacks are not being made.
Has anyone experienced this or had any advice on how I can solve this problem?
EDIT: I also tried the proposed content security policy, but didn't fix the problem:
<meta http-equiv="Content-Security-Policy" content="default-src * gap://ready file:;default-src * 'unsafe-eval'; style-src 'self' 'unsafe-inline'; script-src * 'self' 'unsafe-inline' 'unsafe-eval'" />
EDIT2:
Obj C - , ? , , . Obj. C, , , ( SO) Handler.
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
if(granted){
NSLog(@"Granted access to %@", mediaType);
} else {
NSLog(@"Not granted access to %@", mediaType);
}
EDIT3: JS Code
`const scannerOpts = {
preferFrontCamera: false,
showFlipCameraButton: false,
showTorchButton: true,
torchOn: false,
prompt: "Place a barcode inside the scan area",
resultDisplayDuration: 500,
disableAnimations: true,
disableSuccessBeep: false
};
cordova.plugins.barcodeScanner.scan(
function(scanResult) {
debugger;
resolve(scanResult);
},
function(scanError) {
debugger;
reject(scanError);
},
scannerOpts
);`
!