Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAUI app crashes when scanner invoked on iPhone 15 Pro Max (iOS 17.2.1) #172

Open
tnewell opened this issue Feb 24, 2024 · 5 comments
Open

Comments

@tnewell
Copy link

tnewell commented Feb 24, 2024

This seems to be the same issue using the old library on my old phone. I have the generic MAUI app you get when creating a new MAUI app in Visual Studio. I added a button on the main page to create and display a new page that contains the scanner control, and that page sets the control options in the constructor and waits for a scan. Before adding the button and new page, I verified the app runs on the android emulator as well as my iPhone. Then I added the ZXing package, button and new page. I then re-verified the app compiles and runs on the android emulator. It scans my test QR code without issue. The app runs on the iPhone right up until I click the button to invoke the scanner, then it crashes. I see that others appear to have at least been able to invoke the scanner, so I'm not sure what's up. Perhaps a manifest provisioning issue? Particulars below:

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

Windows 11 Home (x64)

Visual Studio 2022

iPhone 15 Pro Max
iOS v17.2.1

ZXing.Net.Maui.Controls 0.4.0

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"
             x:Class="SandboxMauiApp.ScannerPage"
             Title="Scanner">
    <VerticalStackLayout>

        <zxing:CameraBarcodeReaderView
            x:Name="barcodeScannerView"
            BarcodesDetected="BarcodeScannerView_BarcodesDetected" />
    
        <Button
                x:Name="ScanExitBtn"
                Text="Exit" 
                SemanticProperties.Hint="Exits barcode scanner"
                Clicked="ScanExitBtn_Clicked"
                HorizontalOptions="Fill" />

    </VerticalStackLayout>
</ContentPage>
namespace SandboxMauiApp;

public partial class ScannerPage : ContentPage
{
    public ScannerPage()
    {
	InitializeComponent();
    
        barcodeScannerView.Options = new BarcodeReaderOptions
        {
            Formats = BarcodeFormats.TwoDimensional,
            AutoRotate = true,
            Multiple = true
        };
    }

    private void BarcodeScannerView_BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
    {
        foreach (var barcode in e.Results)
            Console.WriteLine($"Barcodes: {barcode.Format} -> {barcode.Value}");

        Navigation.PopAsync();
    }

    private void ScanExitBtn_Clicked(object sender, EventArgs e)
    {
        Navigation.PopAsync();
    }
}

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 Crash Reporting
=================================================================

Native stacktrace:
=================================================================
0x10066d6e0 - /private/var/containers/Bundle/Application/73854A73-1F50-4120-9E6D-3EB1F63ADB41/SandboxMauiApp.app/Xamarin.PreBuilt.iOS : AppleCryptoNative_X509ImportCollection
0x1006585cc - /private/var/containers/Bundle/Application/73854A73-1F50-4120-9E6D-3EB1F63ADB41/SandboxMauiApp.app/Xamarin.PreBuilt.iOS : AppleCryptoNative_X509ImportCollection
0x1006ac174 - /private/var/containers/Bundle/Application/73854A73-1F50-4120-9E6D-3EB1F63ADB41/SandboxMauiApp.app/Xamarin.PreBuilt.iOS : AppleCryptoNative_X509ImportCollection
0x10066ced0 - /private/var/containers/Bundle/Application/73854A73-1F50-4120-9E6D-3EB1F63ADB41/SandboxMauiApp.app/Xamarin.PreBuilt.iOS : AppleCryptoNative_X509ImportCollection
0x1fa5b8888 - /usr/lib/system/libsystem_platform.dylib :
0x1d7dd2ed0 - /usr/lib/system/libsystem_kernel.dylib :
0x1d7dd2f04 - /usr/lib/system/libsystem_kernel.dylib :

0 d4 ......0A......
0x1d7dac358 03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91 ...T.#...{......
0x1d7dac368 01 d5 ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6 .........{.....
0x1d7dac378 c0 03 5f d6 d0 03 80 d2 01 10 00 d4 03 01 00 54 ..
............T

The app has been terminated.
0x1b0df98f8 - /System/Library/PrivateFrameworks/TCC.framework/TCC :
0x1b0df5814 - /System/Library/PrivateFrameworks/TCC.framework/TCC :
0x1b0dfd1f8 - /System/Library/PrivateFrameworks/TCC.framework/TCC :
0x1fa6bfb44 - /usr/lib/system/libxpc.dylib :
0x1fa6b24b8 - /usr/lib/system/libxpc.dylib :
0x198639380 - /usr/lib/system/libdispatch.dylib :
0x198656b04 - /usr/lib/system/libdispatch.dylib :
0x19864bd40 - /usr/lib/system/libdispatch.dylib :
0x19864b628 - /usr/lib/system/libdispatch.dylib :
0x1fa65f99c - /usr/lib/system/libsystem_pthread.dylib : _pthread_wqthread
0x1fa65fa04 - /usr/lib/system/libsystem_pthread.dylib : start_wqthread

=================================================================
Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x1d7dac358):0x1d7dac348 ff 0f 5f d6 c0 03 5f d6 30 41 80 d2 01 10 0

@tnewell
Copy link
Author

tnewell commented Feb 24, 2024

(* sigh *)

And just like that, it stopped crashing. The scanner control isn't rendered, mind you, but at least it doesn't crash.
I made a few adjustments to the XAML to explicitly declare the camera position and it started not crashing, but when I reverted the code to the original, it continued to work, so I have no idea what happened.

The odd thing is, even though the control isn't rendering, it's there, because I have Hot Reload active and when I modify the XAML to add IsTorchOn="True" and hit save, the light on my phone comes on and goes off if I change the value to "False". But no control is visible on the UI,

Things still work fine in the Android emulator, so I just need to figure out why the control won't render on the UI on my iPhone.

So close. :)

@tnewell
Copy link
Author

tnewell commented Feb 24, 2024

Oh but wait, there's more. Turns out that while the control appears to not be responsive to HorizontalOptions or VerticalOptions, it is responsive to WidthRequest and HeightRequest. While in the Android emulator, no such properties were needed, if you don't set those values, the control is not visible on the iPhone. So now I have a visible control that seems to scan ok.

Still no idea why it stopped crashing, but progress.

@RobFrancisAu
Copy link

Have you tried using a <Grid> rather than a <VerticalStackLayout> ?

@tnewell
Copy link
Author

tnewell commented Mar 15, 2024

For those who come here looking for help regarding using the scanner view on iOS:

  1. Make sure you add ".UseBarcodeReader()" to the chain of methods called when the app is created. I believe this is mentioned on the front page of the Git project, but I forgot about it when migrating and it caused me a lot of unnecessary grief.

  2. IMPORTANT! Make sure you include this key/value pair in the "info.plist" file in the iOS platform folder:

	<key>NSCameraUsageDescription</key>
	<string>Barcode scanning</string>

I am almost 100% sure this is the cause of the crash. I managed to get the Xamarin version working as well after adding this.

I would also suggest you set the "WidthRequest" and "HeightRequest" on the barcode reader control and give them some sane values (I used 360 and 480) to start. This should hopefully let you at least see something and verify the control is working.

Have you tried using a <Grid> rather than a <VerticalStackLayout> ?

I have not, but I may play around with that. I have things working now, so I'm content to leave things in a stack layout for now.

@Vikas-jk
Copy link

Vikas-jk commented Oct 28, 2024

Hello, I am facing same issue and this crash only occurs as soon as I install app on iOS and click on "Allow Camera access" and app crashes.
Once I restart app it works fine.

if I uninstall app and then re-try to give permission it crashes.

How to resolve this? my code is as below, in .xaml file

<zxing:CameraBarcodeReaderView HeightRequest="200" WidthRequest="200" Margin="10" x:Name="cameraBarcodeReaderView" BarcodesDetected="BarcodesDetected" />

and in .cs file

  public PageUpdate()
  {
      InitializeComponent();
      cameraBarcodeReaderView.Options = new BarcodeReaderOptions
      {
          Formats = BarcodeFormats.All,
          AutoRotate = true,
          Multiple = true
      };
  }

 protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
   {
       foreach (var barcode in e.Results)
       {
           Console.WriteLine($"Barcodes: {barcode.Format} -> {barcode.Value}");
       }

  
   Dispatcher.Dispatch(() =>
   {
       GridControl.Add(new Label { Text = $"{e.Results[0].Value}" }, 1, count);
       count++;

     });
    }

I have given permissions in info.list file as mentioned here https://github.com/Redth/ZXing.Net.Maui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants