Exemplo n.º 1
0
        public async Task <bool> OpenBrowser(string url, BrowserOptions options = null)
        {
            try
            {
                if (options == null)
                {
                    options = new BrowserOptions();
                }

                if ((options?.UseSafariWebViewController ?? false) && UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                {
                    // create safari controller
                    var sfViewController = new SFSafariViewController(new NSUrl(url), options?.UseSafariReaderMode ?? false);

                    // apply custom tint colors
                    if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
                    {
                        var barTintColor = options?.SafariBarTintColor;
                        if (barTintColor != null)
                        {
                            sfViewController.PreferredBarTintColor = barTintColor.ToUIColor();
                        }

                        var controlTintColor = options?.SafariControlTintColor;
                        if (controlTintColor != null)
                        {
                            sfViewController.PreferredControlTintColor = controlTintColor.ToUIColor();
                        }
                    }

                    // show safari controller
                    var vc = GetVisibleViewController();

                    if (sfViewController.PopoverPresentationController != null)
                    {
                        sfViewController.PopoverPresentationController.SourceView = vc.View;
                    }

                    await vc.PresentViewControllerAsync(sfViewController, true);
                }
                else
                {
                    UIApplication.SharedApplication.OpenUrl(new NSUrl(url));
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to open browser: " + ex.Message);
                return(false);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> OpenBrowser(string url, BrowserOptions options = null)
        {
            try
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri(url));

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to open browser: " + ex.Message);
                return(false);
            }
        }
Exemplo n.º 3
0
        public Task <bool> OpenBrowser(string url, BrowserOptions options = null)
        {
            try
            {
                if (options == null)
                {
                    options = new BrowserOptions();
                }

                if (Platform.CurrentActivity == null)
                {
                    var intent = new Intent(Intent.ActionView);
                    intent.SetData(global::Android.Net.Uri.Parse(url));

                    intent.SetFlags(ActivityFlags.ClearTop);
                    intent.SetFlags(ActivityFlags.NewTask);
                    Platform.CurrentContext.StartActivity(intent);
                }
                else
                {
                    var tabsBuilder = new CustomTabsIntent.Builder();
                    tabsBuilder.SetShowTitle(options?.ChromeShowTitle ?? false);

                    var toolbarColor = options?.ChromeToolbarColor;
                    if (toolbarColor != null)
                    {
                        tabsBuilder.SetToolbarColor(toolbarColor.ToNativeColor());
                    }

                    var intent = tabsBuilder.Build();
                    intent.LaunchUrl(Platform.CurrentActivity, global::Android.Net.Uri.Parse(url));
                }

                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to open browser: " + ex.Message);
                return(Task.FromResult(false));
            }
        }
Exemplo n.º 4
0
 public Task <bool> OpenBrowser(string url, BrowserOptions options = null)
 {
     throw new System.NotImplementedException();
 }