Redth / ZXing.Net.Mobile

Barcode Scanner for Xamarin.iOS, Xamarin.Android, UWP and Tizen
MIT License
1.07k stars 703 forks source link

Scanning not working for ios #895

Open cissemy opened 4 years ago

cissemy commented 4 years ago

Here is my code : public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); } private async void Scan_Clicked(object sender, EventArgs e) {

    var scanner = new MobileBarcodeScanner();

    var result = await scanner.Scan();

                    if (result != null)
                    {
                        await DisplayAlert("Scanned Barcode", result.Text, "OK");
                    }

} } In AppDeletegate.cs : public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); LoadApplication(new App());

        return base.FinishedLaunching(app, options);
    }

Thanks

stavroaudi commented 4 years ago

Same issue. Mine crashes after a barcode is scanned on iOS. Device tested: iPhone 11 Pro Max 13.4.1

stavroaudi commented 4 years ago

Fixed my issue by changing my result handler:

    public void Handle_OnScanResult(Result result)
    {
        BarcodeScanView.IsScanning = false;
        Device.BeginInvokeOnMainThread(async () =>
        {
            if (string.IsNullOrWhiteSpace(result.Text))
                return;
                // handle result
        }
     }
cissemy commented 4 years ago

It is the same as this one but still it does not work : private async void Scan_Clicked(object sender, EventArgs e) { var scanPage = new ZXingScannerPage(); scanPage.Title = "Scanner"; scanPage.OnScanResult += result => { scanPage.IsScanning = false;

            Device.BeginInvokeOnMainThread(async () =>
            {
                await Navigation.PopAsync();
                if (string.IsNullOrWhiteSpace(result.Text))
                    await DisplayAlert("Scanned Barcode", result.Text, "OK");
               // mycode.Text = result.Text;
            });
        };
        await Navigation.PushAsync(scanPage);

    }
knocte commented 4 years ago

@cissemy what version of ZXing.Net.Mobile are you using?

dnguyen2k commented 3 years ago

Have anyone get ZXing.Net.Mobile scanner to work? I tried every which way possible and still, it doesn't scan on both Android or iOS device. I am using the latest version of Xamarin.Forms 5.0.x.x and latest ZXing.Net.Mobile package. Any help is greatly apprecitated.