How to properly use "UseMauiCompatibility()" to port from Xamarin.iOS to MAUI?

Markus Friese 20 Reputation points
2024-01-22T17:23:53.64+00:00

Hello community, I am trying to port an example from https://github.com/xamarin/ios-samples/tree/main/ios11/AVCamBarcode to .Net MAUI. You can find my implementation here: https://filetransfer.io/data-package/Yy9kBIuy#link I can load the storyboard, create the controller but my app will freeze, when putting it on the navigation stack and I cannot tell why. What else do I need to get this up and running? It work find in a xamarin.form app by the way. Regards!

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,913 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 48,181 Reputation points Microsoft Vendor
    2024-01-23T07:24:53.04+00:00

    Hello,

    After step-by-step debugging, this issue is caused by the camera view not being pushed to the page.

    After you create the camera view, the MainPage is pushed again in the source code, causing the page to not display the camera.

    // run this on the main thread ...
    Shell.Current.Navigation.PushAsync(contentPage);
    

    To fix this issue, you need to push the camera view into the navigation stack to display it.

    Microsoft.Maui.ApplicationModel.Platform.GetCurrentUIViewController().PresentModalViewController(cameraViewController,true);
    

    Note: For camera-related features, you could only test them on a physical device.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.