EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

Help - MLKitBarcodeScanner scans QR code, but always returns an empty result #1811

Closed michaelsmedley closed 3 years ago

michaelsmedley commented 3 years ago

Hi

I'm currently trying to implement the Barcode scanner functionality to scan QR codes using the live camera.

I have the app using the camera and picking up the QR codes (I can tell this is working as the app beeps when a QR code is in view of the camera). However, the value of the result.values object is always {"barcodes":[]}. This is so far happening on iOS, I don't have an Android device to test on.

To help debugging, my project is built with Nativescript-vue, I am using version 10.5.2 of the plugin, and my iOS platform is 6.5.2.

This is the markup I have in place on my template:

<template>
  <Page>
    <ActionBar title="QR Code Scanner" icon="">
      <NavigationButton
        icon="res://baseline_menu_white_24"
        @tap="onDrawerButtonTap"
      />
    </ActionBar>

    <MLKitBarcodeScanner
      width="260"
      height="380"
      :beepOnScan="true"
      :preferFrontCamera="false"
      :supportInverseBarcodes="false"
      :torchOn="false"
      :processEveryNthFrame="100"
      @scanResult="onBarcodeScanningResult"
    >
    </MLKitBarcodeScanner>
  </Page>
</template>

<script>
export default {
  data() {
    return {
      torchOn: false,
      scanned: false,
    };
  },
  methods: {
    onBarcodeScanningResult(res) {
      console.log(
        "🚀 ~ file: QrScanner.vue ~ line 35 ~ onBarcodeScanningResult ~ res",
        JSON.stringify(res.value)
      );
      if (res.barcodes && res.barcodes.length > 0) {
        console.log(
          "🚀 ~ file: QrScanner.vue ~ line 32 ~ onBarcodeScanningResult ~ res",
          JSON.stringify(res.barcodes)
        );
        this.scanned = true;
      }
    },
  },
};
</script>

Like I say, the scanner does load and does appear to differentiate between a QR code, so I think the configuration is correct, it's just not processing the barcode for some reason.

An example barcode I am using can be found at the bottom of https://firebase.google.com/docs/ml-kit/read-barcodes - this barcode is loading fine with my iOS camera app, and is beeping within my project, but not pulling back any details about the barcode.

If anyone is able to help talk me through this I would be grateful

image

michaelsmedley commented 3 years ago

OK, leaving the project and coming back, it seems that codes are scanning now.

I'm not sure if it's down to me being more patient with trying to scan the QR code from a computer screen, or if me specifying the formats in my component, it seems to be playing today, so going to close.

Thanks to anyone who took a look at this