コード例 #1
0
        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);
        }
コード例 #2
0
            static async Task closeSFSafariViewController(SFSafariViewController?safariViewController)
            {
                await(safariViewController?.DismissViewControllerAsync(true) ?? Task.CompletedTask).ConfigureAwait(false);

                safariViewController?.Dispose();
                safariViewController = null;
            }