Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Last active Mar 26, 2019
Embed
What would you like to do?
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