xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 506 forks source link

[Bug] Launcher.CanOpenAsync returns false for custom urls on iOS #1350

Closed MichaelRumpler closed 4 years ago

MichaelRumpler commented 4 years ago

Description

I open other apps via urls. Until recently I used Device.OpenUrl for that, but now that method is marked as obsolete.

OpenUri is obsolete as of version 4.3.0. Use Launcher.OpenAsync (or CanOpenAsync, or TryOpenAsync) from Xamarin.Essentials instead.

I tried to follow the warning and replace it with Launcher.CanOpenAsync and Launcher.OpenAsync or with TryOpenAsync, but the Can.. and Try.. methods always return false for uri schemes which are handled by third party apps. They only return true for some standard schemes like http, https and mailto.

Steps to Reproduce

  1. Install an app which handles its own url scheme - e.g. Termius
  2. Try to open an url which is handled by that app - e.g. await Launcher.CanOpenAsync("ssh://...")

Expected Behavior

It returns true. Launcher.OpenAsync or Launcher.TryOpenAsync start Termius.

Actual Behavior

It returns false. Nothing is started.

Basic Information

Reproduction Link

Repro_Launcher.zip The sample app tries to open some urls which are handled by various third party apps. You can choose with the radio buttons at the top whether it uses the Launcher or Device.OpenUrl to open the urls so that you can verify that the url really works. I added some comments in MainPage.xaml.cs with the apps which handle the urls in question.

jamesmontemagno commented 4 years ago

Did you add these into your LSApplicationQueriesSchemes? https://docs.microsoft.com/en-us/xamarin/essentials/launcher?context=xamarin%2Fxamarin-forms&tabs=ios#additional-platform-setup

MichaelRumpler commented 4 years ago

No, I didn't see that. Thanks, that fixed the issue.

Why is that needed for the Launcher, but not for Device.OpenUrl?

jamesmontemagno commented 4 years ago

To check "CanOpen" you must use those. You can launch without checking, which is what OpenUrl and OpenAsync does...

https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html

rajeshangappan commented 2 years ago

I have added the LSApplicationQueriesSchemes still same issue