Custom HTML not showing on iOS

IOS doesn't show custom html when I assign it to the HtmlWebViewSource:

            webView.Source = new HtmlWebViewSource
            {
                Html = "Hello world"
            };

In Android works fine but in ios doesn't. What should I do to fix it?

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I tested this code:

        public App()
        {
            // The root page of your application
            MainPage = new ContentPage {
                Content = new WebView { Source = new HtmlWebViewSource { Html = "Hello, World" } },
            };
        }
    

    And I ended up with this:
    image

    That seems to be working so something isn't adding up. Could you attach an example project showing what you're trying?

  • I solved the problem it seems the cause is the Navigating method that i used:

        webView.Navigating += (s, e) =>
                {
                    e.Cancel = true;
    
                    Device.OpenUri(new Uri(e.Url));
                };
    

    This callback blocks the webview in iOS, what can I do to prevent it the first time?

  • adamkempadamkemp USInsider, Developer Group Leader mod

    You could do something as simple as this:

    bool navigatedOnce = false;
    webView.Navigating += (s, e) =>
            {
                if (navigatedOnce)
                {
                    e.Cancel = true;
    
                    Device.OpenUri(new Uri(e.Url));
                }
    
                navigatedOnce = true;
            };
    
  • JassimRahmaJassimRahma USMember ✭✭✭

    I have the same problem and Navigating did not solve it for me

Sign In or Register to comment.