Beispiel #1
0
        protected UIView PrepareWKWebView()
        {
            WebKit.WKWebViewConfiguration wk_web_view_configuration = null;


            wk_web_view_configuration = new WebKit.WKWebViewConfiguration();

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                wk_web_view_configuration.WebsiteDataStore = WKWebsiteDataStore.NonPersistentDataStore;
            }

            wk_web_view = new WebKit.WKWebView(View.Frame, wk_web_view_configuration)
            {
                UIDelegate         = new WKWebViewUIDelegate(this),
                NavigationDelegate = new WKWebViewNavigationDelegate(this),
                AutoresizingMask   = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
            };

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                //  cheating!
                //  http://www.useragentstring.com/pages/useragentstring.php?typ=Browser
                wk_web_view.CustomUserAgent = WebViewConfiguration.IOS.UserAgent;
            }

            web_view = wk_web_view;


            return(web_view);
        }
Beispiel #2
0
        //COSMOS
        //protected UIView PrepareUIWebView()
        //{
        //    ui_web_view = new UIWebView(View.Bounds)
        //    {
        //        Delegate = new UIWebViewDelegate(this),
        //        AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
        //    };
        //    web_view = ui_web_view;
        //    View.AddSubview((UIWebView)web_view);

        //    return web_view;
        //}

        protected UIView PrepareWKWebView()
        {
            WebKit.WKWebViewConfiguration wk_web_view_configuration = null;

            if
            (
                ObjCRuntime.Class.GetHandle("WKWebView") != IntPtr.Zero
                &&
                UIDevice.CurrentDevice.CheckSystemVersion(8, 0)
            )
            {
                wk_web_view_configuration = new WebKit.WKWebViewConfiguration();

                if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                {
                    wk_web_view_configuration.WebsiteDataStore = WKWebsiteDataStore.NonPersistentDataStore;
                }

                // COSMOS
                wk_web_view_configuration.UserContentController = GetUserContentController();
                // ------

                wk_web_view = new WebKit.WKWebView(View.Frame, wk_web_view_configuration)
                {
                    UIDelegate         = new WKWebViewUIDelegate(this),
                    NavigationDelegate = new WKWebViewNavigationDelegate(this),
                    AutoresizingMask   = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,

                    // COSMOS
                    AllowsBackForwardNavigationGestures = true
                };

                // COSMOS
                //if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                //{
                //    //  cheating!
                //    //  http://www.useragentstring.com/pages/useragentstring.php?typ=Browser
                //    wk_web_view.CustomUserAgent = WebViewConfiguration.IOS.UserAgent;
                //}

                web_view = wk_web_view;
            }
            // COSMOS
            //        else
            //        {
            //            // Fallback to Embedded WebView
            //            StringBuilder msg = new StringBuilder();
            //            msg.AppendLine("WKWebView not available!");
            //            msg.AppendLine("Fallback to UIWebView");

            //this.ShowErrorForNativeUIAlert(msg.ToString());

            //            web_view = PrepareUIWebView();
            //        }


            return(web_view);
        }
            static void UserAgentFromWKWebView()
            {
                WebKit.WKWebViewConfiguration wkconf = new WebKit.WKWebViewConfiguration()
                {
                };
                WebKit.WKWebView wkwv = new WebKit.WKWebView(CoreGraphics.CGRect.Empty, wkconf);

                // TODO: WKWebKit UserAgent JavaScript handler not triggered from JavaScript
                WebKit.WKJavascriptEvaluationResult handler = HandleWKJavascriptEvaluationResult;
                // case sensitive stuff:
                //      navigator.*
                // few SO posts with Pascal case will not work!
                wkwv.EvaluateJavaScript((NSString)"navigator.userAgent", handler);
                //wkwv.EvaluateJavaScript((NSString)"navigator.appName", handler);

                wkwv.LoadHtmlString("<html></html>", null);

                return;
            }
Beispiel #4
0
        public WebAuthenticatorController(WebAuthenticator authenticator, bool is_using_wkwebview)
        {
            WebViewConfiguration.IOS.IsUsingWKWebView = is_using_wkwebview;

            this.authenticator = authenticator;

            authenticator.Error             += HandleError;
            authenticator.BrowsingCompleted += HandleBrowsingCompleted;

            //
            // Create the UI
            //
            if (authenticator.AllowCancel)
            {
                NavigationItem.LeftBarButtonItem =
                    new UIBarButtonItem
                    (
                        UIBarButtonSystemItem.Cancel,
                        delegate
                {
                    Cancel();
                    #region
                    //---------------------------------------------------------------------------------------
                    /// Pull Request - manually added/fixed
                    ///		OAuth2Authenticator changes to work with joind.in OAuth #91
                    ///		https://github.com/xamarin/Xamarin.Auth/pull/91
                    ///
                    DismissViewControllerAsync(true);
                    ///---------------------------------------------------------------------------------------
                    #endregion
                }
                    );
            }

            activity = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.White);
            NavigationItem.RightBarButtonItem = new UIBarButtonItem(activity);

            if (WebViewConfiguration.IOS.IsUsingWKWebView == false)
            {
                #if DEBUG
                StringBuilder sb1 = new StringBuilder();
                sb1.Append("Embedded WebView using - UIWebView");
                System.Diagnostics.Debug.WriteLine(sb1.ToString());
                #endif

                ui_web_view = new UIWebView(View.Bounds)
                {
                    Delegate         = new UIWebViewDelegate(this),
                    AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
                };
                web_view = ui_web_view;
                View.AddSubview((UIWebView)web_view);
            }
            else
            {
                #if DEBUG
                StringBuilder sb1 = new StringBuilder();
                sb1.Append("Embedded WebView using - WKWebView");
                System.Diagnostics.Debug.WriteLine(sb1.ToString());
                #endif

                var wk_web_view_configuration = new WebKit.WKWebViewConfiguration();

                if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                {
                    wk_web_view_configuration.WebsiteDataStore = WKWebsiteDataStore.NonPersistentDataStore;
                }

                wk_web_view = new WebKit.WKWebView(View.Frame, wk_web_view_configuration)
                {
                    UIDelegate         = new WKWebViewUIDelegate(this),
                    NavigationDelegate = new WKWebViewNavigationDelegate(this),
                    AutoresizingMask   = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
                    //  cheating!
                    //  http://www.useragentstring.com/pages/useragentstring.php?typ=Browser
                    CustomUserAgent = WebViewConfiguration.IOS.UserAgent,
                };
                web_view = wk_web_view;
                View.AddSubview((WKWebView)web_view);
            }
            #if DEBUG
            authenticator.Title = "Auth " + web_view.GetType().ToString();
            #endif

            Title = authenticator.Title;
            View.BackgroundColor = UIColor.Black;

            // InvalidOperation - either delegates or events!
            //this.webView.LoadFinished += WebView_LoadFinished;
            //
            // Locate our initial URL
            //
            BeginLoadingInitialUrl();

            #if DEBUG
            StringBuilder sb = new StringBuilder();
            sb.AppendLine($"WebAuthenticatorController ");
            sb.AppendLine($"        WebViewConfiguration.IsUsingWKWebView = {WebViewConfiguration.IOS.IsUsingWKWebView}");
            sb.AppendLine($"        authenticator.IsUsingNativeUI         = {authenticator.IsUsingNativeUI}");
            sb.AppendLine($"        authenticator.Title                   = {authenticator.Title}");
            System.Diagnostics.Debug.WriteLine(sb.ToString());
            #endif

            return;
        }