Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Last active March 26, 2019 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinZikmund/f98ab77195ba0b0161daae67e7ca7936 to your computer and use it in GitHub Desktop.
Save MartinZikmund/f98ab77195ba0b0161daae67e7ca7936 to your computer and use it in GitHub Desktop.
public static partial class Launcher
{
public static async Task<bool> LaunchUriAsync(Uri uri)
{
try
{
#if __IOS__
return UIKit.UIApplication.SharedApplication.OpenUrl(new global::Foundation.NSUrl(uri.OriginalString));
#elif __ANDROID__
var androidUri = global::Android.Net.Uri.Parse(uri.OriginalString);
var intent = new global::Android.Content.Intent(global::Android.Content.Intent.ActionView, androidUri);
((Android.App.Activity)Uno.UI.ContextHelper.Current).StartActivity(intent);
return true;
#elif __WASM__
var command = $"Uno.UI.WindowManager.current.open(\"{uri.OriginalString}\");";
var result = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
return result == "True";
#else
throw new NotImplementedException();
#endif
}
catch (Exception exception)
{
if (typeof(Launcher).Log().IsEnabled(LogLevel.Error))
{
typeof(Launcher).Log().Error($"Failed to {nameof(LaunchUriAsync)}.", exception);
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment