Open HugoHeneault opened 6 years ago
+1 for this.
The underlying plugins (ZXing and AVFoundation) used by this cordova plugin are all supporting many types of barcodes, so this could be "easily" implemented for Android, iOS and Windows Phone, only the browser platform wouldn't support it. I privateley forked this and built in this functionality for my current project for Android, but it's not ready to publish yet and I don't know, if I'll publish it ever.
Actually, it's already working. You'll have to edit the plugins files manually, but it's worth it :)
Here's what you need to change:
platforms/ios/{{YOUR_APP_NAME}}/Plugins/cordova-plugin-qrscanner/QRScanner.swift
metaOutput!.metadataObjectTypes = [AVMetadataObjectTypeQRCode]
by
metaOutput!.metadataObjectTypes = [AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeCode128Code]
And
if found.type == AVMetadataObjectTypeQRCode || && found.stringValue != nil {
by
if (found.type == AVMetadataObjectTypeQRCode || found.type == AVMetadataObjectTypeEAN13Code) {{ OR WHATEVER CODES YOU NEED }} && found.stringValue != nil {
just add it in the formatList array of platforms/android/src/com/bitpay/cordova/qrscanner/QRScanner.java
ArrayList<BarcodeFormat> formatList = new ArrayList<BarcodeFormat>();
formatList.add(BarcodeFormat.EAN_13);
formatList.add(BarcodeFormat.CODE_128);
This should be more documented, though... :)
@HugoHeneault
Original code in platforms/ios/{{YOUR_APP_NAME}}/Plugins/cordova-plugin-qrscanner/QRScanner.swift
should be:
metaOutput!.metadataObjectTypes = [AVMetadataObjectTypeQRCode]
And ONE MORE LINE need to change in IOS
if found.type == AVMetadataObjectTypeQRCode || && found.stringValue != nil {
change into
if (found.type == AVMetadataObjectTypeQRCode || found.type == AVMetadataObjectTypeEAN13Code) && found.stringValue != nil {
@sonicwong Thanks a lot for your updates. I edited my post. 🍻
how about in browser? where can I add this for browser?
Hi all, while the focus of the plugin will remain QR codes, PRs are certainly welcome to add other types. 🚀
As mentioned above, the native platforms basically support other codes already, we're just not enabling them.
The browser version will require quite a bit more work, though, and would likely cause a performance hit. I'd be open to PRs there though, too.
In browser, I used quagga.js. In your plugin for browser, you just had put an alert form, So I used quaggaJS there.
I tried this solution for DATA_MATRIX
ArrayList<BarcodeFormat> formatList = new ArrayList<BarcodeFormat>();
formatList.add(BarcodeFormat.QR_CODE);
formatList.add(BarcodeFormat.DATA_MATRIX);
But it does not work. Seems like cordova does not recompile plugins, because if I delete QR_CODE at all, it still work and decodes it
Solved by remove/add platform
iOS Code for plugin v3.0.1
metaOutput!.metadataObjectTypes = [AVMetadataObject.ObjectType.qr, AVMetadataObject.ObjectType.ean13, AVMetadataObject.ObjectType.code128, AVMetadataObject.ObjectType.code39]
if ((found.type == AVMetadataObject.ObjectType.qr || found.type == AVMetadataObject.ObjectType.ean13 || found.type == AVMetadataObject.ObjectType.code128 || found.type == AVMetadataObject.ObjectType.code39) && found.stringValue != nil) {
@sonicwong thanks,This problem has been solved by your response
Just packed all mod files here: https://github.com/sonicwong/cordova-plugin-qrscanner-add-barcode
Feel free to use.
This is really important now that PhoneGap is dead and the phonegap/phonegap-plugin-barcodescanner repo is read-only. I've been going crazy trying to find a good replacement that is still maintained.
As you provide a really nice way of scanning QR code and keep the view behind the webview, it would be awesome that you support barcodes too 👍
There is an issue opened on the barcode scanner to use the same thing as you did but they doesn't seem to manage it as of now... https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/223