Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
This repository was archived by the owner on May 15, 2024. It is now read-only.

Launcher.OpenAsync Crashes on iOS  #794

@rkshnair

Description

@rkshnair

Launcher.OpenAsync(uri); method call crashes / throws an exception in case any space in the query url.

The issue is only present in iOS. Android everything working as expected.

My button click event

async void Handle_Clicked(object sender, System.EventArgs e)
        {
            string url = string.Empty;
            switch (Device.RuntimePlatform)
            {
                case Device.iOS:
                    url = $"https://maps.apple.com/maps?q=Ole Vigs Gate 8B";
                    break;
                case Device.Android:
                    url = $"https://maps.google.com/maps?q=Ole Vigs Gate 8B";
                    break;
            }
            await LaunchApplicationAsync(url);
        }

Launcher call

 public async Task LaunchApplicationAsync(string uri)
        {
            try
            {
                await Launcher.OpenAsync(uri);
            }
            catch (Exception ex)
            {
                //Ignore
            }
        }

Stack Trace.

{System.Exception: Could not initialize an instance of the type 'Foundation.NSUrl': the native 'initWithString:' method returned nil.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
at Foundation.NSObject.InitializeHandle (System.IntPtr handle, System.String initSelector) [0x000a8] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSObject2.cs:504
at Foundation.NSUrl..ctor (System.String urlString) [0x00023] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSUrl.g.cs:139
at Xamarin.Essentials.Launcher.PlatformOpenAsync (System.Uri uri) [0x0000b] in :0
at Xamarin.Essentials.Launcher.OpenAsync (System.String uri) [0x00019] in :0
at LauncherIssue.MainPage.LaunchApplicationAsync (System.String uri) [0x00018] in /Users/rakeshrnair/Projects/LauncherIssue/LauncherIssue/MainPage.xaml.cs:30 }

I can reproduce the issue in all iOS devices.

Metadata

Metadata

Labels

awaiting-reviewThis PR needs to have a set of eyes on itbugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions