Redth / ZXing.Net.Mobile

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

QR code not recognizable in iOS #949

Open AndreaGobs opened 3 years ago

AndreaGobs commented 3 years ago

Below is the working code for an Android QR scanner. In iOS I tried different combinations of AutoRotate, TryHarder, TryInverted, DelayBetweenContinuousScans and DelayBetweenAnalyzingFrames but with no result. Removing the QR_CODE format from options, iOS is able to scan eg EAN_13 but never QR_CODE.

Page view: <Grid> <zxing:ZXingScannerView x:Name="zxing" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" OnScanResult="zxing_OnScanResult"/> <zxing:ZXingDefaultOverlay x:Name="overlay" TopText = "Hold your phone up to the barcode" BottomText = "Scanning will happen automatically" ShowFlashButton="True" FlashButtonClicked="overlay_FlashButtonClicked"/> </Grid>

Page code: `[XamlCompilation(XamlCompilationOptions.Compile)] public partial class PageScan : ContentPage { public PageScan() { InitializeComponent(); }

protected override void OnAppearing()
{
    base.OnAppearing();

    zxing.IsAnalyzing = true;
    zxing.IsScanning = true;
    zxing.Options = new MobileBarcodeScanningOptions
    {
        PossibleFormats = new List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.QR_CODE },
        //DelayBetweenContinuousScans = 20,
        //DelayBetweenAnalyzingFrames = 20,
        DisableAutofocus = false,
        //AutoRotate = false,
        TryHarder = true,
        //TryInverted = false,
        UseFrontCameraIfAvailable = false,
        //AssumeGS1 = true,
        //UseNativeScanning = true
    };
}

protected override void OnDisappearing()
{
    zxing.IsScanning = false;

    base.OnDisappearing();
}

private void zxing_OnScanResult(ZXing.Result result)
{
    zxing.IsAnalyzing = false;

    Device.BeginInvokeOnMainThread(async () =>
    {
        Console.WriteLine("QRPAGE | " + result.Text + " " + result.BarcodeFormat);
        await Navigation.PushAsync(new PageResult(result.Text));
        await DisplayAlert("Qr scan result", result.Text, "OK");
    });
}

private async void overlay_FlashButtonClicked(Button sender, EventArgs e)
{
    if (Device.RuntimePlatform == Device.iOS)
    {
        //workaround for iOS torch
        await ToggleFlashIos();
    }
    else
    {
        zxing.IsTorchOn = !zxing.IsTorchOn;
    }
}

}`

iOS version of my iPhone7 13.3.1 Xamarin.Forms 4.8 Xamarin.Essentials 1.5 ZXing.Net.Mobile & ZXing.Net.Mobile.Forms 3.0.0-beta5

Any suggestions?

knocte commented 3 years ago

ZXing.Net.Mobile & ZXing.Net.Mobile.Forms 3.0.0-beta5

Does it work in 2.4.x stable version?

AndreaGobs commented 3 years ago

Does it work in 2.4.x stable version?

I tried before to upgrade to 3.0.0-beta5. In Android also the stable version works for me with the options above, but not on iOS

knocte commented 3 years ago

I tried before to upgrade to 3.0.0-beta5

I didn't ask about 3.x, you already said you were using this version.

In Android also the stable version works for me, but not on iOS

So the bug is in both stable and beta, right?

AndreaGobs commented 3 years ago

Yes

chuckgiddens commented 3 years ago

I have the same issue with same versions of iOS as above. Tried latest stable and beta versions and works fine in Android but not iOS. The camera works but the QRCode never is read in iOS. But perfect in Android.

meJevin commented 3 years ago

@chuckgiddens, this is still an issue. I'm trying out the samples provided but no luck on iOS devices. Creating another issue to bump.

AndreaGobs commented 3 years ago

Meanwhile, my personal solution: xamarin forms scanner