Redth / ZXing.Net.Mobile

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

iOS 15.4 - Xamarin.iOS - Crash when scanning with AVCaptureEngine #1035

Open Koub96 opened 2 years ago

Koub96 commented 2 years ago

Hello.

Once I updated my device to iOS 15.4, I get the following runtime exception when trying to scan using the AVCaptureEngine. I use the latest available stable version 2.4.1.

System.Exception: System.NotSupportedException: Codabar has no associated enum value on this platform. at AVFoundation.AVMetadataObjectTypeExtensions.GetValue (Foundation.NSString constant) [0x0015b] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/AVFoundation/AVMetadataObjectType.g.cs:420 at AVFoundation.AVMetadataObject.ArrayToEnum (Foundation.NSString[] arr) [0x00016] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/AVFoundation/AVMetadataObject.cs:51 at AVFoundation.AVCaptureMetadataOutput.get_AvailableMetadataObjectTypes () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/AVFoundation/AVCaptureMetadataOutput.cs:39 at ZXing.Mobile.AVCaptureScannerView.SetupCaptureSession () [0x0041b] in <04e0b9ffeac840b494808f043a3ab5ba>:0 at ZXing.Mobile.AVCaptureScannerView.b__36_0 () [0x00001] in <04e0b9ffeac840b494808f043a3ab5ba>:0 at Foundation.NSActionDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:62 at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr_bool(intptr,intptr,intptr,intptr,bool) at Foundation.NSObject.InvokeOnMainThread (System.Action action) [0x00007] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:619 at ZXing.Mobile.AVCaptureScannerView.StartScanning (System.Action`1[T] scanResultHandler, ZXing.Mobile.MobileBarcodeScanningOptions options) [0x00047] in <04e0b9ffeac840b494808f043a3ab5ba>:0 at ZXing.Mobile.AVCaptureScannerViewController.ViewDidAppear (System.Boolean animated) [0x0006a] in <04e0b9ffeac840b494808f043a3ab5ba>:0 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)

MFinkBK commented 2 years ago

I also got this, and the a workaround would be to explicitly set the PossibleFormats options value to the list of iOS-supported barcode formats. Then the else block that accesses AvailableMetadataObjectTypes isn't called:

https://github.com/Redth/ZXing.Net.Mobile/blob/f8abca8d7e4d0e1e76b6ba6b9418545aa2085036/ZXing.Net.Mobile/iOS/AVCaptureScannerView.ios.cs#L238

I don't know what the solution would be, since the crash happens inside AVCaptureMetadataOutput.cs, which is a Xamarin.iOS project, and isn't contained in ZXing.Net.Mobile.

Glorfindel83 commented 2 years ago

I had a similar problem (not using ZXing but rather iOS built-in scanning) with the same error message (Codabar has no associated enum value on this platform) but I could solve it by simply rebuilding the application with the latest version of Xamarin.iOS (15.8).

MFinkBK commented 2 years ago

Thanks for the update! It seems the Xamarin.iOS - Xcode 13.3 update added some other barcodes with AVFoundation as well: https://github.com/xamarin/xamarin-macios/pull/14325

Koub96 commented 2 years ago

Thanks for the update! It seems the Xamarin.iOS - Xcode 13.3 update added some other barcodes with AVFoundation as well: xamarin/xamarin-macios#14325

Thank you all for your quick replies.

To overcome this issue, I stopped using the AVCaptureEngine through the scan(bool useAVCaptureEngine) method. Instead, I now set this method parameter to false and I am using the (custom I suppose) implementation of the ZXing.Net.Mobile, so I can keep scanning codabar barcodes.

To your knowledge, is there any downside to not use the AVCaptureEngine through the scan(bool useAVCaptureEngine) method?

MFinkBK commented 2 years ago

I have the impression that the AVCaptureEngine is faster than the ZXing library when specifying all barcodes, so I try to continue using it.

imsam67 commented 2 years ago

I'm using this library on an Xamarin Forms 5 app and everything works fine on Android. But if I connect my iPhone Xs to my PC via USB for debug, it doesn't scan at all. It simply doesn't do anything! I then packaged the app for TestFlight testing and installed it on my iPhone Xs, and it crashed the whole app. Here's my SO question about this issue: https://stackoverflow.com/questions/71977226/zxing-scanner-not-scanning-on-ios-in-xamarin-forms-app

Does anyone have a solution for this issue?