Redth / ZXing.Net.Mobile

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

[Question] ZXing does not work in ".Net 8 for iOS" - "MobileBarcodeScanner is unsupported on this platform" #1085

Closed jbouche-work closed 4 months ago

jbouche-work commented 4 months ago

Hi,

After migrate my Xamarin.iOS app (Xamarin Native, not Xamarin Forms) to .Net 8 for iOS (.Net for native, not MAUI), ZXing scan with the MobileBarcodeScanner do an exception with the error message : "MobileBarcodeScanner is unsupported on this platform".

Is ZXing expected to work with the MobileBarcodeScanner in .Net 8 for iOS ? If not, what other library allows you to scan QRCode in .Net8 for iOS ?

Thank you in advance for your feedback. Best regards

pmlemay commented 4 months ago

@jbouche-work Hello, I was also experiencing issues with .net8 QR code scanning crashing saying to use the specific implementation for each platform when trying to use the .Scan method. For some reasons we do not have access to use this public method in the MobileBarcodeScanner.ios.cs : Scan(bool useAVCaptureEngine) which can solve the problem. For now my solution is copying all the code in my own project and using this scan method is now possible and works. I had to change some deprecated code like the AVCaptureDevice, here's an exemple of that:

AVCaptureDeviceType[] deviceTypes = new AVCaptureDeviceType[] {
    AVCaptureDeviceType.BuiltInTrueDepthCamera,
    AVCaptureDeviceType.BuiltInDualCamera,
    AVCaptureDeviceType.BuiltInWideAngleCamera
};
AVCaptureDeviceDiscoverySession discoverySession = AVCaptureDeviceDiscoverySession.Create(deviceTypes,        
    AVMediaType.Video, AVCaptureDevicePosition.Back);
AVCaptureDevice[] devices = discoverySession.Devices;
AVCaptureDevice device = devices.FirstOrDefault();
jbouche-work commented 4 months ago

@jbouche-work Hello, I was also experiencing issues with .net8 QR code scanning crashing saying to use the specific implementation for each platform when trying to use the .Scan method. For some reasons we do not have access to use this public method in the MobileBarcodeScanner.ios.cs : Scan(bool useAVCaptureEngine) which can solve the problem. For now my solution is copying all the code in my own project and using this scan method is now possible and works. I had to change some deprecated code like the AVCaptureDevice, here's an exemple of that:

AVCaptureDeviceType[] deviceTypes = new AVCaptureDeviceType[] {
    AVCaptureDeviceType.BuiltInTrueDepthCamera,
    AVCaptureDeviceType.BuiltInDualCamera,
    AVCaptureDeviceType.BuiltInWideAngleCamera
};
AVCaptureDeviceDiscoverySession discoverySession = AVCaptureDeviceDiscoverySession.Create(deviceTypes,        
    AVMediaType.Video, AVCaptureDevicePosition.Back);
AVCaptureDevice[] devices = discoverySession.Devices;
AVCaptureDevice device = devices.FirstOrDefault();

Hi,

Thanks a lot for your response, I just tested it and it works perfectly. Looks like all that's left to do is make a PR ;) (But there is a lot of deprecated stuff...).

Thank you very much for your response ^^.

PS : I hope that in the next month we will have a new ZXing nuget .Net8.0-ios and android ready ^^.

pmlemay commented 3 months ago

Hi @AtinAgarwal1981,

You cannot use the nuget at this moment since it is not up to date for .net8, what we did is to download the source code from here, include it in your project and fix the compilation bugs (I posted one of the exemple bugs fixes). You can then use the right methods (or even change the code so that it always takes the "useAVCaptureEngine" parameter by default so that it always works for .net8 iOS