internal static Task <BrowserResult> Start(BrowserOptions options) { var tcs = new TaskCompletionSource <BrowserResult>(); // Create Safari controller var safari = new SFSafariViewController(new NSUrl(options.StartUrl)) { Delegate = new SafariViewControllerDelegate() }; async void Callback(string response) { ActivityMediator.Instance.ActivityMessageReceived -= Callback; if (response == "UserCancel") { tcs.SetResult(Canceled()); } else { await safari.DismissViewControllerAsync(true); // Close Safari safari.Dispose(); tcs.SetResult(Success(response)); } } ActivityMediator.Instance.ActivityMessageReceived += Callback; // Launch Safari FindRootController().PresentViewController(safari, true, null); return(tcs.Task); }
static async Task closeSFSafariViewController(SFSafariViewController?safariViewController) { await(safariViewController?.DismissViewControllerAsync(true) ?? Task.CompletedTask).ConfigureAwait(false); safariViewController?.Dispose(); safariViewController = null; }