Reputation: 2189
For a project I am working on there has to be a way to scan QR-Codes. I've got this one from the phonegap-plugin-barcodescanner. As is, it works well on Android, never had any problems.
But on iOs it will crash as is. You will get a request to use the camera, and then the app crashes. The way I found around this is to remove the options part of it, then it works.
This looks like a bit of a strange way to solve it. Question: is there a better way to solve this?
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
},
{
"preferFrontCamera" : true, // iOS and Android
"showFlipCameraButton" : true, // iOS and Android
"prompt" : "Place a barcode inside the scan area", // supported on Android only
"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
}
);
Using: Windows 10, Intel XDK v3619, Cordova CLI 6.2.0 and phonegap-plugin-barcodescanner 4.1.0
Upvotes: 0
Views: 2066
Reputation: 53
I have also had crash issues with cordova-plugin-barcodescanner on IOS 10 via Phonegap Build.
Solved now after hours of trying, I had to add the cordova-plugin-camera first and then the cordova-plugin-barcodescanner.
Here's the relevant extract my working config.xml:
<meta http-equiv="Content-Security-Policy" content="default-src * gap: file:; style-src 'self' 'unsafe-inline'; img-src 'self' data: gap:; script-src * 'unsafe-inline' 'unsafe-eval'">
<plugin name="cordova-plugin-camera" spec="~2.3.1">
<variable name="CAMERA_USAGE_DESCRIPTION" value="My App would like to access your camera, to take photos of your documents." />
</plugin>
<preference name="android-build-tool" value="gradle" />
<plugin name="cordova-plugin-barcodescanner">
<variable name="CAMERA_USAGE_DESCRIPTION" value="abc123" />
</plugin>
On both Android6 and IOS10 the example of GitHub is now working well: https://github.com/phonegap/phonegap-plugin-barcodescanner
Upvotes: 2