Redth / ZXing.Net.Mobile

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

ZXingScannerView dont show on some apple devices (Xamarin forms) #987

Open rr-rv opened 3 years ago

rr-rv commented 3 years ago

versions: ZXing.Net.Mobile 2.4.1 and 3.1.0-beta2 ZXing.Net.Mobile.Forms 2.4.1 and 3.1.0-beta2 Xamarin.Forms 5.0.0.2021 iPad Air 2 14.X (tried ios 14.1 and 14.4) Edit iPhone SE

Setup: ContenPage -> Grid -> ZXingScannerView

ini:

var barcodeOptions = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                PossibleFormats = { BarcodeFormat.QR_CODE },
            };
            //AppControl.OnPlatformSwitch(ios, android, other)
            barcodeOptions.UseNativeScanning = AppControl.OnPlatformSwitch(true, false, true);
            barcodeOptions.TryHarder = AppControl.OnPlatformSwitch(false, true, false);
            barcodeOptions.DelayBetweenContinuousScans = AppControl.OnPlatformSwitch(200, 100, 200);

            _scanView = new ZXing.Net.Mobile.Forms.ZXingScannerView() { Options = barcodeOptions, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Fill, IsScanning = true, };

problem On iPad the scanner works, but does not show the camera view.

it works fine on iPhones in ios 14.1 and 14.4 with no problems (and on android as well) edit Just had the chance to test on a more modern iPad (gen 3 pro) where it also works w/o problems. This is getting more and more wierd edit2 Now i have a iPhone SE where the view also dont show.

Expected behavior That the camera preview is shown on iPad

attachemts. file1 is ss from a iPhone file2 is ss from iPad file1 file2

delember commented 3 years ago

Hi @rr-rv,

I stumbled across the same issue today. On my Android phone (Samsung Galaxy S10+, Android 11) the ScannerView showed fine but on an iPad (5th Generation, iPadOS 14.5.1) the camera feed was not displayed although the iPadOS reported active access to the camera.

After extensive searching, I found a hint in the Xamarin Forums with a possible solution to this problem here. It mentions that changing the HorizontalOptions to FillAndExpand could help. I set both this and the VerticalOptions to FillAndExpand, because I want the camera view to be fullscreen anyway.

In my case, that solution worked. Maybe you give that approach a shot and see whether it solves your issue.

Hope this helps, have a nice day!

Jan


That's my XAML code (but this should work in C#-Code as well):

<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    <forms:ZXingScannerView ScanResultCommand="{Binding CodeScannedCommand}"
        IsScanning="{Binding IsScanning}" Options="{Binding ScanningOptions}"
        VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />
</Grid>
rr-rv commented 3 years ago

hi @delember

thanks for your idea!!

i did try the fillAndExpand, also putting it inside a StackLayout(and a scroll and a abs layout) and deleting the grid altogether w/o any luck. (as these steps sometimes work in xamarin.forms)

and as you point out, the camera is very much active and getting "read" by the scanner, so the view is somewhere on that page.

i ended up rewriting the solution to use the inbuilt scanner page instead as i could not get the view to work reliably.