0

Net.Mobile to implement barcode scanning into an app.

I currently have a little demo app that has implemented a scanning page, I can read barcodes and do something. I'm using Xamarin Forms to implement the barcode scanning. I looked at the sample app provided by ZXing and copied the code for one of their scanners to use in my demo. Now i have tested this app in android, I'm using an API 21 phone and it lags like hell but all in all it works. I can scan a barcode and navigate to a new screen.

When testing on iOS (using an iphone 6 on the latest version - 11.2.5) I noticed that the iphone never stops reading barcodes. Here is the code that get called when the phone recognises a barcode:

zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread(async () => {

// Stop analysis until we navigate away so we don't keep reading barcodes
zxing.IsAnalyzing = false;

// Show an alert
await DisplayAlert("Scanned Barcode", result.Text, "OK");

// Navigate away
await Navigation.PushAsync(new ScanResultsPage());

});

So as you can see the first thing that gets called when a barcode is recognised is zxing.IsAnalyzing = false;, this works on android. However on iOS it continues scanning and if I point the phone at the barcode, more and more alerts get added to the screen. I am new to Xamarin Forms and have never encountered any issues when adding barcodes to iOS natively.

I don't really know where to begin debugging this, I put a breakpoint on this line of code zxing.IsAnalyzing = false;, it executes and I can see the value is set to false.

Could this be an issue with the ZXing framework itself?

Thanks

(I have called init in the app delegate)

Bodungus
  • 175
  • 14

1 Answers1

0

Refer to sample usage , I think you should add scanPage.IsScanning = false; to stop scanning.

scanPage.OnScanResult += (result) => {
// Stop scanning
    scanPage.IsScanning = false;

    // Pop the page and show the result
    Device.BeginInvokeOnMainThread (() => {
        await Navigation.PushAsync(new ScanResultsPage());       
        DisplayAlert("Scanned Barcode", result.Text, "OK");
    });
};
ColeX
  • 14,062
  • 5
  • 43
  • 240
  • setting scanning to false stops the scanner altogether (disables the camera). In the sample app and in android `scanner.IsAnalyzing = false;` works. It is only in iOS that is doesn't stop scanning... – Bodungus Feb 09 '18 at 10:57
  • Unfortunately this doesn't seem to work. Exactly the same issue, the boolean gets set to false but the code decides to execute anyway. I raised this as an issue on github and will be implementing native iOS scanning (using apples superior frameworks) – Bodungus Feb 13 '18 at 09:46