0
votes

I am testing WebView in my Xamarin iOS app project. The WebView is coded like this:

<WebView
    x:Name="WebView"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand" 
    android:WebView.EnableZoomControls="true"
    android:WebView.DisplayZoomControls="false"   
>
</WebView>

The WebView can display html:

 WebView.Source = new HtmlWebViewSource
            {
                Html = "<!DOCTYPE html><html><body><p>Hello world</p></body></html>",
            };

But when I use a URL:

WebView.Source = new HtmlWebViewSource() { BaseUrl = "https://www.google.com" };

or

WebView.Source = "https://www.google.com";

I only get a blank area.

I have added this to the info.plist:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
    </dict>

I don't handle any events such as Navigate, Navigating etc. Also, I am not overriding the WebView in this simple test.

The iPhone can display google.com and other sites when I open Safari.

What could the problem be?

1
Hi for confirmation, did you set horizontal options and vertical options?Anand
Yes. I have added the markup to the question now.Rugbrød
Could it work with other url ?And make sure that network permissions are turned on.Leo Zhu - MSFT

1 Answers

0
votes

Add a public property in your viewModel like this:

private string _uri;
    public string Uri
    {
        get { return _uri; }
        set { SetProperty(ref _uri, value); }
    }

Then assign and address to it like this:

Uri = "http://google.com";

preferably in the onNavigated to

In your xaml add this

<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="5"> <WebView Source="{Binding Uri}"></WebView> </Grid>