WebView not showing html web page in simulator

DaveYDaveY USUniversity ✭✭

I have the following xaml

`<?xml version="1.0" encoding="utf-8" ?>

<ContentPage.Content>

  <!--<Label x:Name="message" Text="here" VerticalOptions="Center" HorizontalOptions="Center" />-->

  <WebView x:Name="webView1"
           HeightRequest="100"
           WidthRequest="100"
           HorizontalOptions="FillAndExpand"
           VerticalOptions="FillAndExpand"              
           />


  <WebView Source="http://www.xamarin.com/"
    HeightRequest="1000"
    WidthRequest="1000" />

  <!--<WebView x:Name="webView"></WebView>-->

  <Button Text="Next" Clicked="Nav_OnClick" BackgroundColor="Gray"  TextColor="White"></Button>

</StackLayout>

</ContentPage.Content>
`

In the code behind i am setting the source of webView1 via the following...neither webviews show the html content from the internet.

var URLReportsListWebView = new UrlWebViewSource { Url = "http://www.yahoo.com/" }; webView1.BackgroundColor = Xamarin.Forms.Color.Transparent; webView1.Source = URLReportsListWebView;

Is there any particular reason for this issue? (all i see in the simulator is a blank screen)

Posts

  • DaveYDaveY USUniversity ✭✭

    I tried this sample as well and the webview still does not show any html
    https://github.com/mobilewits/How-to-implement-a-webview-in-Xamarin.Forms/tree/master/WebViewXamarinForms

    I am running the beta version (channel), visual studio 2015, xcode 7.1 and xamarin forms 1.5

    Ideas?

  • Quan.HoangQuan.Hoang USMember

    @DaveY I'm not sure what you are attempting to do, but UrlWebViewSource is pretty simple to show.

        var webView = new WebView {
            Source = new UrlWebViewSource {
                url = "http://Xamarin.com",
            },
    };
    

    or if you want to do html

        var webView = new WebView {
                Source = new HtmlWebViewSource {
                    Html = htmlSource,
            },
        };
    
  • DaveYDaveY USUniversity ✭✭

    That is the same code as mine. I am using ios9 (deploying to iphone6 or ipad air2 simulator).
    Still have a blank screen.
    Oddly - if set the html to show it displays correctly so I am thinking there is some permission setting I need to set to allow xamarin to reach out and load content from the web. I found this similar post about ios 9 but still not working.
    https://forums.xamarin.com/discussion/51801/ios-9-is-still-now-working-with-webview-now

  • DaveYDaveY USUniversity ✭✭
    edited October 2015

    This appears to be the issue http://developer.xamarin.com/recipes/ios/content_controls/web_view/load_a_web_page/

    I was seeing the following in my output window when running
    " App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure"

    If you set the source to https://{url} then all works well..you will get the above issue when you try to set source to http://{url}. There appears to be some configuration needed if you want to browse/open http addresses.

    I added following to info.plist at the bottom

    <plist> ......{stuff up here}... <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> </dict> </plist>

    It is working now.

  • Quan.HoangQuan.Hoang USMember

    That was going to be my next suggestion was to check the web access security. I'm glad you figured it out.

Sign In or Register to comment.