Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I pressed the button once on iOS, but it is executed more than 3 times by Scan Default. #609

Closed
ghost opened this issue Aug 21, 2017 · 4 comments

Comments

@ghost
Copy link

ghost commented Aug 21, 2017

Xamarin.Forms
ZXing.Net.Mobile.Forms 2.2.9
Forms.iOS
iPhone iOS 10.3.3

I pressed the button once in the iOS environment and the scan is executed two or three times.
I want the scanner to run once.

your Sample :
buttonScanDefaultOverlay.Clicked += async delegate {
scanPage = new ZXingScannerPage ();
scanPage.OnScanResult += (result) => {
scanPage.IsScanning = false;

	--2 or 3 over Times Run
	Device.BeginInvokeOnMainThread (() => {
		scanPage.IsAnalyzing = false;
		Navigation.PopAsync();
		Debug.WriteLine("=============="+ result.Text + "=================");
		DisplayAlert("Scanned Barcode", result.Text, "OK");
	});
};

await Navigation.PushAsync (scanPage);

};

2017-08-21 17:31:43.567 FormsSampleiOS[1096:174134] ZXingScannerView.Setup() took 0.214 ms.
2017-08-21 17:31:43.568 FormsSampleiOS[1096:174134] StartScanning
2017-08-21 17:31:43.632 FormsSampleiOS[1096:174134] PERF: Alloc AVCaptureVideoPreviewLayer took 5.67 ms.
Thread started: #3
Thread started: #4
[0:] ==============FD11102=================
Thread started: #5
[0:] ==============FD11102=================
[0:] ==============FD11102=================
[0:] ==============FD11102=================
2017-08-21 17:31:45.612 FormsSampleiOS[1096:174134] Stopping...

@AlexDarbyFujitsuGmail
Copy link

AlexDarbyFujitsuGmail commented Aug 23, 2017

I am getting the same issue and I have the latest Xamarin VS and iOS.

@ghost
Copy link
Author

ghost commented Aug 24, 2017

suggest version 2.1.47

@peterianhall
Copy link

peterianhall commented Sep 14, 2017

I had the same issue in a Xamarin Forms project and the multiple call only happening on iOS. I tried downgrading to 2.1.47 but still had the same problem. The OnScanResult event wasn't always called exactly three times though, it varied but was almost always more than 1.

I saw a suggestion elsewhere to set the DelayBetweenContinuousScans value on MobileBarcodeScanningOptions when creating the scanner page but this also didn't work.

I eventually worked around it by rearranging the code slightly so the event handler removed itself the first time it was called and this seemed to fix it. Something like this....

ZXingScannerPage scanPage = null;

async void OnScanButtonClicked(object sender, EventArgs e)
{
    scanPage = new ZXingScannerPage();
    scanPage.OnScanResult += ScanPage_OnScanResult;
    await Navigation.PushAsync(scanPage);
}

async void ScanPage_OnScanResult(ZXing.Result result)
{
    scanPage.IsScanning = false;
    scanPage.OnScanResult -= ScanPage_OnScanResult;
    Xamarin.Forms.Device.BeginInvokeOnMainThread(async () =>
    {
        await Navigation.PopAsync();
        Debug.WriteLine("=============="+ result.Text + "=================");
    });
}

@Redth
Copy link
Owner

Redth commented Mar 13, 2020

Thanks for reporting this issue! Unforunately it took me way too long to respond 😭. Sorry, I apologize! Recently the source code for this project was completely refactored to modernize it. Many PR's were included in this effort, and many bugs were hopefully fixed. Please try out the latest 3.x series of NuGet packages (currently in prerelease). To try and make the project more maintainable in my spare time going forward, I've decided to close all existing issues to start with a clean slate. If you're still experiencing this issue on the newest version, please open a new issue with as much detail as possible. Thank you for your patience and understanding! Happy scanning!

@Redth Redth closed this as completed Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants