Redth / ZXing.Net.Maui

Barcode Scanning for MAUI?
MIT License
461 stars 151 forks source link

IOS App Crash After Scanning #120

Open LeonWill95 opened 1 year ago

LeonWill95 commented 1 year ago

This project works brilliantly in Android, we are having a problem in iOS, if you open the form, close it, its fine, if you click outside the scanner to close the form its works fine, if you open the form and then scan a QR it crashes the code after the result has been saved and the form closes which in turn crashes the app completely.

Is there any barcode scanner that works in iOS and Maui Blazor / Maui?

iPhone Xr iOS 16.31
Model Number MRY42B/A

xCode 14.2 Microsoft Visual Studio Version 17.5.3 .net 7


2023-04-12 12:31:32.443 MauiMixBlazorSample[554:4637344] Unhandled managed exception: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread. (UIKit.UIKitThreadAccessException) at UIKit.UIApplication.EnsureUIThread() at UIKit.UIViewController.DismissViewController(Boolean animated, Action completionHandler) at UIKit.UIViewController.DismissViewControllerAsync(Boolean animated) at CommunityToolkit.Maui.Core.Handlers.PopupHandler.MapOnClosed(PopupHandler handler, IPopup view, Object result) in /_/src/CommunityToolkit.Maui.Core/Handlers/Popup/PopupHandler.macios.cs:line 19 at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() at System.Threading.Thread.StartCallback()

================================================================= Native Crash Reporting

Got a SIGABRT while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.

================================================================= Native stacktrace:

            0x102c15494 - /private/var/containers/Bundle/Application/0DA0F614-4CB2-416D-B956-DB1528E990D1/MauiMixBlazorSample.app/MauiMixBlazorSample : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
            0x102c00590 - /private/var/containers/Bundle/Application/0DA0F614-4CB2-416D-B956-DB1528E990D1/MauiMixBlazorSample.app/MauiMixBlazorSample : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
            0x102d28de4 - /private/var/containers/Bundle/Application/0DA0F614-4CB2-416D-

B956-DB1528E990D1/MauiMixBlazorSample.app/MauiMixBlazorSample : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode 0x102c14ca8 - /private/var/containers/Bundle/Application/0DA0F614-4CB2-416D-B956-DB1528E990D1/MauiMixBlazorSample.app/MauiMixBlazorSample : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode 0x2105c3a90 - /usr/lib/system/libsystem_platform.dylib : 0x21065f1ac - /usr/lib/system/libsystem_pthread.dylib : pthread_kill 0x1c9a5cc8c - /usr/lib/system/libsystem_c.dylib : abort 0x10291dbd0 - /private/var/containers/Bundle/Application/0DA0F614-4CB2-416D-B956-DB1528E990D1/MauiMixBlazorSample.app/MauiMixBlazorSample : xamarin_find_protocol_wrapper_type 0x102af8898 - /private/var/containers/Bundle/Application/0DA0F614-4CB2-416D-B956-DB1528E990D1/MauiMixBlazorSample.app/MauiMixBlazorSample : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode 0x102 b4b1fc - /private/var/containers/Bundle/Application/0DA0F614-4CB2-416D-B956-DB1528E990D1/MauiMixBlazorSample.app/MauiMixBlazorSample : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode 0x102b4af48 - /private/var/containers/Bundle/Application/0DA0F614-4CB2-416D-B956-DB1528E990D1/MauiMixBlazorSample.app/MauiMixBlazorSample : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode 0x2106596cc - /usr/lib/system/libsystem_pthread.dylib : _pthread_start 0x210658ba4 - /usr/lib/system/libsystem_pthread.dylib : thread_start

================================================================= Basic Fault Address Reporting

Memory around native instruction pointer (0x1ffefb674):0x1ffefb664 ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4 .......)...... 0x1ffefb674 03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91 ...T.#...{...... 0x1ffefb684 09 ed ff 97 bf 0 The app has been terminated. 3 00 91 fd 7b c1 a8 ff 0f 5f d6 .........{..... 0x1ffefb694 c0 03 5f d6 7f 23 03 d5 fd 7b bf a9 fd 03 00 91 ....#...{......

================================================================= Managed Stacktrace:

=================================================================

rajeshsws commented 1 year ago

Use methods Device.BeginInvokeOnMainThread(()

private void scanner_BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) { try { Device.BeginInvokeOnMainThread(() => { scanner.IsDetecting = false; SecureStorage.Default.SetAsync("Camera", Switch.IsToggled.ToString()); this.Close(e.Results[0].Value); });

    }
    catch
    {

    }

}
SKIDDOW commented 1 year ago

Try this https://github.com/hjam40/Camera.MAUI

raconn commented 1 year ago

Getting the same on iOS 16.4, iPhone Pro 14. Wrapped in Device.BeginInvokeOnMainThread(() as suggested above. Just launching causes crash with no methods called for detection. Thanks