bitpay / cordova-plugin-qrscanner

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps and the browser.
MIT License
568 stars 772 forks source link

Add support for other types of barcodes? #132

Open HugoHeneault opened 6 years ago

HugoHeneault commented 6 years ago

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

RafaelKr commented 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.

HugoHeneault commented 6 years ago

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:

iOS

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 {

Android

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... :)

sonicwong commented 6 years ago

@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 {

HugoHeneault commented 6 years ago

@sonicwong Thanks a lot for your updates. I edited my post. 🍻

omkarkhalipe commented 6 years ago

how about in browser? where can I add this for browser?

bitjson commented 6 years ago

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.

omkarkhalipe commented 6 years ago

In browser, I used quagga.js. In your plugin for browser, you just had put an alert form, So I used quaggaJS there.

JuliaRakitina commented 5 years ago

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

JuliaRakitina commented 5 years ago

Solved by remove/add platform

sonicwong commented 5 years ago

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) {

sunhongjian commented 4 years ago

@sonicwong thanks,This problem has been solved by your response

sonicwong commented 4 years ago

Just packed all mod files here: https://github.com/sonicwong/cordova-plugin-qrscanner-add-barcode

Feel free to use.

skylarmt commented 3 years ago

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.