dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Maui Blazor for iOS works on macbook from command line but fails to start when installed on Iphone using TestFlight. Using IConnectivity, IGeolocation, IMediaPicker #7945

Closed myndfire closed 1 year ago

myndfire commented 2 years ago

Description

I have added 3 pages to the default Maui Blazor template app (files attached). Build IDE: Visual Studio Professional 2022 for Mac Preview Version 17.3 Preview (17.3 build 198)

Build Host: Macbook Air (M1)

When I run from vs2022 in debug mode all works, however in release mode nothing happens.

Steps to Reproduce

  1. Create a new Maui Blazor app
  2. add platform capabilities in DI container
        builder.Services.AddSingleton<IConnectivity>(Connectivity.Current);
        builder.Services.AddSingleton<IGeolocation>(Geolocation.Default);
        builder.Services.AddSingleton<IMediaPicker>(MediaPicker.Default);
  3. Added 3 buttons for each of the services
  4. Added code to access these services that are called from the button callbacks:
    public bool IsThereConnectivity()
        {
            if (connectivity.NetworkAccess != NetworkAccess.Internet)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

                Location location;
                await CheckAndRequestLocationPermission();
                location = await geolocation.GetLastKnownLocationAsync();
                if (location == null)
                {
                    location = await geolocation.GetLocationAsync(
                        new GeolocationRequest
                        {
                            DesiredAccuracy = GeolocationAccuracy.Medium,
                            Timeout = TimeSpan.FromSeconds(30)
                        }
                            );
                }
                return location;

if (mediaPicker.IsCaptureSupported)
                {
                    FileResult photo = await MediaPicker.Default.CapturePhotoAsync();

                    if (photo != null)
                    {
                        // save the file into local storage
                        string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);

                        using Stream sourceStream = await photo.OpenReadAsync();
                        using FileStream localFileStream = File.OpenWrite(localFilePath);
                        Result = localFilePath;
                        await sourceStream.CopyToAsync(localFileStream);
                        return Result;
                    }
                }
  1. Updated info.plist:

        <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to location services</string>
    <key>NSCameraUsageDescription</key>
    <string>This app needs access to the camera to take photos.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>This app needs access to microphone for taking videos.</string>
    <key>NSPhotoLibraryAddUsageDescription</key>
    <string>This app needs access to the photo gallery for picking photos and videos.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>This app needs access to photos gallery for picking photos and videos.</string>
  2. Ran local release on my macboor air (M1) dotnet build -t:Run -c:Release -f net6.0-maccatalyst MyMauiBlazorApp.csproj ALL WORKS FINE IN THE APP !

  3. Created archive for iOS

dotnet publish MyMauiBlazorApp.csproj -f:net6.0-ios -c:Release /p:ServerAddress=<my macbook ip address> p:ServerUser=<username> /p:TcpPort=58181 /p:ArchiveOnBuild=true /p:_DotNetRootRemoteDirectory=/Users/<username>/Library/Caches/Xamarin/XMA/SDKs/dotnet/ /p:EnableAssemblyILStripping=false /p:ServerPassword=<macbook user password>
  1. Used transporter/testflight to publish
  2. Installed the app on my iphone 12 pro max using TestFlight

==============. FAILS ===========

  1. When I try to open the app, the app flashes the screen and then closes
  2. If I undo all my changes and install the default Maui Blazor app all works fine.

Kindly advice.

Version with bug

7.0 Release Candidate 1 or older

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

macOS 12.3.1 (21E258)

Did you find any workaround?

No

Relevant log output

No response

arthastheking113 commented 2 years ago

I have the same issue.

Working fine is Android both in simulator and physical devices.

On iOS, work fine in simulator, got error in TestFlight.

Get rejected from Apple Review team since it could not pass the flash screen.

I could not reproduce the error in the simulator.

I wonder if this is because of I published the app using my m1 Mac.

My publish settings

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
        <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
        <MtouchUseLlvm>False</MtouchUseLlvm>
        <!-- Only needed when you have a need for entitlements -->
        <!-- <CodesignEntitlement>Entitlements.plist</CodesignEntitlement> -->
        <CodesignKey>Apple Distribution: {My Name} ({My Code})</CodesignKey>
        <CodesignProvision>{My App Code}</CodesignProvision>
        <ServerAddress>{My Server Address}</ServerAddress>
        <ServerUser>{My Server User}</ServerUser>
        <ServerPassword>{My Server Password}</ServerPassword>
        <TcpPort>58181</TcpPort>
        <ArchiveOnBuild>true</ArchiveOnBuild>
        <BuildIpa>true</BuildIpa>
    <_DotNetRootRemoteDirectory>/Users/{My Server User}/Library/Caches/Xamarin/XMA/SDKs/dotnet/</_DotNetRootRemoteDirectory>

</PropertyGroup>

My publish command: sudo dotnet publish -c:Release -f:net6.0-ios

I sent my .ipa file to Apple using Transporter.

myndfire commented 2 years ago

any workaround?

sencagri commented 2 years ago

Same here not working on real device

JawadJaber commented 2 years ago

Same issue here, after sending to TestFlight then every thing crashes

JawadJaber commented 2 years ago

Hello Try using interpreter as discussed and confirmed here

https://github.com/dotnet/maui/issues/9597

myndfire commented 2 years ago

Thanks @JawadJaber. Will try and post the results.

myndfire commented 2 years ago

Confirmed that it works. Appreciate it @JawadJaber

mattleibow commented 1 year ago

Duplicate of #9597

christallire commented 1 year ago

@mattleibow please reopen this issue since referring issue is closed and locked or create a real issue not working on iOS since this is very urgent and blocking. The interpreter is not a solution, you know. it crashes everywhere we use linq, serialization. It basically breaks the MULTIPLATFORM 'M' part of MAUI.

ghost commented 1 year ago

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

christallire commented 1 year ago

I created https://github.com/dotnet/maui/issues/12353 for your convenience