Last active
March 26, 2019 19:38
-
-
Save MartinZikmund/f98ab77195ba0b0161daae67e7ca7936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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