async Task method() { var auth = new FacebookAuthenticator( "2063574180384090", "email", this); var authenticator = auth.GetAuthenticator(); var viewController = authenticator.GetUI(); _navigationStack = ((AppDelegate)_Managers[0]).Window.RootViewController; SafariServices.SFSafariViewController c = null; c = (SafariServices.SFSafariViewController)viewController; viewController = c; _navigationStack.PresentViewController(viewController, true, null); //if (result.Authenticated) //{ // ExecuteCallBack(new FingerPrint { IsValid = true }); //} //else //{ // OnError(new string[] { ServiceKey + " Reported " + result.Status.ToString(), result.ErrorMessage }); //} }
private async void OpenBrowser(string url) { try { if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { var sfViewController = new SafariServices.SFSafariViewController(new NSUrl(url), true); var vc = GetVisibleViewController(); if (sfViewController.PopoverPresentationController != null) { sfViewController.PopoverPresentationController.SourceView = vc.View; } await vc.PresentViewControllerAsync(sfViewController, true); } else { if (UIApplication.SharedApplication.CanOpenUrl(new NSUrl(url))) { UIApplication.SharedApplication.OpenUrl(new NSUrl(url)); } } } catch (Exception ex) { Mvx.Resolve <MvvmCross.Platform.Platform.IMvxTrace>().Trace(MvvmCross.Platform.Platform.MvxTraceLevel.Error, $"{GetType().FullName}\n", ex.StackTrace); } }
/// <summary> /// Open a browser to a specific url /// </summary> /// <param name="url">Url to open</param> /// <param name="options">Platform specific options</param> /// <returns>awaitable Task</returns> public async Task OpenBrowser(string url, BrowserOptions options = null) { try { if (options == null) { options = new BrowserOptions(); } if ((options?.UseSafariWebViewController ?? false) && UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { var sfViewController = new SafariServices.SFSafariViewController(new NSUrl(url), options?.UseSafairReaderMode ?? false); var vc = GetVisibleViewController(); if (sfViewController.PopoverPresentationController != null) { sfViewController.PopoverPresentationController.SourceView = vc.View; } await vc.PresentViewControllerAsync(sfViewController, true); } else { UIApplication.SharedApplication.OpenUrl(new NSUrl(url)); } } catch (Exception ex) { Console.WriteLine("Unable to open browser: " + ex.Message); } }
private void GoToGitHub() { var url = new NSUrl(CodeHubUrl); var viewController = new SafariServices.SFSafariViewController(url); PresentViewController(viewController, true, null); }
public override void ViewDidLoad() { base.ViewDidLoad(); var safariBrowser = new SafariServices.SFSafariViewController(new NSUrl(ViewModel.Url)); safariBrowser.View.Frame = View.Bounds; safariBrowser.View.AutoresizingMask = UIKit.UIViewAutoresizing.All; AddChildViewController(safariBrowser); Add(safariBrowser.View); }
void ButtonLoginCustomTabsOAuth2_TouchUpInside(object sender, EventArgs e) { SetUpDataPublicNonSensitive(); SetUpDataPrivateSensitiveSecret(); Foundation.NSUrl nsurl = new Foundation.NSUrl(url); SafariServices.SFSafariViewController vc = null; vc = new SafariServices.SFSafariViewController(nsurl, true); PresentViewController(vc, true, null); return; }
protected AuthenticateUIType GetPlatformUINative() { System.Uri uri_netfx = this.GetInitialUrlAsync().Result; Foundation.NSUrl url_ios = new Foundation.NSUrl(uri_netfx.AbsoluteUri); // SafariServices.SFSafariViewController AuthenticateUIType ui = null; global::SafariServices.SFSafariViewController sfvc = null; if ( // double check (trying to lookup class and check iOS version) ObjCRuntime.Class.GetHandle("SFSafariViewController") != IntPtr.Zero && UIKit.UIDevice.CurrentDevice.CheckSystemVersion(9, 0) ) { sfvc = new global::SafariServices.SFSafariViewController(url_ios, false); #if DEBUG this.Title = "Auth " + sfvc.GetType().ToString(); System.Diagnostics.Debug.WriteLine($"SFSafariViewController.Title = {this.Title}"); #endif sfvc.Delegate = new NativeAuthSafariViewControllerDelegate(this); sfvc.Title = this.Title; ui = sfvc; } else { // Fallback to Embedded WebView StringBuilder msg = new StringBuilder(); msg.AppendLine("SafariViewController not available!"); msg.AppendLine("Fallback to embbeded web view "); this.ShowErrorForNativeUIAlert(msg.ToString()); this.GetPlatformUIEmbeddedBrowser(); } return(ui); }
public override void ViewDidLoad() { base.ViewDidLoad(); var vm = ViewModel as WebBrowserViewModel; System.Uri uri; if (!System.Uri.TryCreate(vm.Url, System.UriKind.Absolute, out uri)) { AlertDialogService.ShowAlert("Error", "Unable to display webpage as the provided link (" + vm.Url + ") was invalid"); } else { var safariBrowser = new SafariServices.SFSafariViewController(new NSUrl(vm.Url)); safariBrowser.View.Frame = View.Bounds; safariBrowser.View.AutoresizingMask = UIViewAutoresizing.All; AddChildViewController(safariBrowser); Add(safariBrowser.View); } }
async void LoginButton_TouchUpInside(object sender, EventArgs e) { var authority = "https://demo.identityserver.io"; var options = new OidcClientOptions( authority, "native", "secret", "openid profile api", "io.identitymodel.native://callback"); _client = new OidcClient(options); _state = await _client.PrepareLoginAsync(); AppDelegate.CallbackHandler = HandleCallback; safari = new SafariServices.SFSafariViewController(new NSUrl(_state.StartUrl)); this.PresentViewController(safari, true, null); }
async void LoginButton_TouchUpInside(object sender, EventArgs e) { var options = new OidcClientOptions { Authority = "https://demo.identityserver.io", ClientId = "native.hybrid", Scope = "openid profile email api", RedirectUri = "io.identitymodel.native://callback", ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect }; _client = new OidcClient(options); _state = await _client.PrepareLoginAsync(); AppDelegate.CallbackHandler = HandleCallback; safari = new SafariServices.SFSafariViewController(new NSUrl(_state.StartUrl)); this.PresentViewController(safari, true, null); }
public virtual void OpenUrl(Uri url) { if (url == null) { throw new ArgumentNullException(nameof(url)); } #if Android var mgr = new Android.Support.CustomTabs.CustomTabsActivityManager((Android.App.Activity)_context); mgr.CustomTabsServiceConnected += delegate { mgr.LaunchUrl(url.ToString()); }; mgr.BindService(); return; #elif iOS Foundation.NSUrl destination = Foundation.NSUrl.FromString(url.AbsoluteUri); using (SafariServices.SFSafariViewController sfViewController = new SafariServices.SFSafariViewController(destination)) { UIKit.UIWindow window = UIKit.UIApplication.SharedApplication.KeyWindow; UIKit.UIViewController controller = window.RootViewController; controller.PresentViewController(sfViewController, true, null); return; } #else if (_deviceService.RuntimePlatform == RuntimePlatform.Android || _deviceService.RuntimePlatform == RuntimePlatform.iOS) { throw new InvalidOperationException($"Register {nameof(DefaultBrowserService)} using platform specific {nameof(IPlatformInitializer)}"); } _deviceService.OpenUri(url); #endif }
protected AuthenticateUIType GetPlatformUINative() { System.Uri uri_netfx = this.GetInitialUrlAsync().Result; Foundation.NSUrl url_ios = new Foundation.NSUrl(uri_netfx.AbsoluteUri); // SafariServices.SFSafariViewController AuthenticateUIType ui = null; global::SafariServices.SFSafariViewController sfvc = null; sfvc = new global::SafariServices.SFSafariViewController(url_ios, false); #if DEBUG this.Title = "Auth " + sfvc.GetType().ToString(); System.Diagnostics.Debug.WriteLine($"SFSafariViewController.Title = {this.Title}"); #endif sfvc.Delegate = new NativeAuthSafariViewControllerDelegate(this); sfvc.Title = this.Title; ui = sfvc; return(ui); }