Webview does not load css and images on iOS

EwoudvdWerfEwoudvdWerf USMember ✭✭✭

It does load the css and images on Android, not on iOS however


  • MommMomm USMember ✭✭✭

    @EwoudvdWerf What's their url? Are they using https? Perhaps iOS is blocking it.

    Change your info.plist and add NSAllowsArbitraryLoads to it.

    Please let me know if it helps you.

  • EwoudvdWerfEwoudvdWerf USMember ✭✭✭

    @Momm i added NSAllowsArbitraryLoads (and have it set to "yes"), but it still doesn't work, this is the url: http://www.topentwelonline.nl/

  • RyanDixonRyanDixon USMember ✭✭✭

    @EwoudvdWerf said:
    @Momm i added NSAllowsArbitraryLoads (and have it set to "yes"), but it still doesn't work, this is the url: http://www.topentwelonline.nl/

    Can we see some code? Are you using the standard WebView provided by Xamarin (based on UIWebView) or are you using a third party one like XLabs or my FormsWebView?

    Most of the time as Felipe said, this is because the resources are loaded from an insecure URL and iOS prevents it in iOS 9 onwards, but you can have issues where the source is simple set incorrectly. (i.e the BaseUrl could be trying to resolve external resources from the app itself)

  • EwoudvdWerfEwoudvdWerf USMember ✭✭✭

    var HTMLSource = new HtmlWebViewSource(); HTMLSource.BaseUrl = "http://www.topentwelonline.nl/"; HTMLSource.Html = "{very long HTML code here}"; Prikbordview.Source = HTMLSource;

  • RyanDixonRyanDixon USMember ✭✭✭

    Ah I see! Apologies if I get the wrong idea.
    HTMLWebViewSource is used to provide a website as string data to the WebView. The BaseURL is what UIWebView will use to find the paths of the images and css in which you are missing. Although this is the case on Android, UIWebView is an outdated component and generally support around this hasn't really improved in a long time!

    Can you try setting the source purely as a string value as see if that works?
    I would try on iOS but I am currently on a Windows only network :smile:

    If this fails still, you could always try using or creating a HybridWebView to make use of the newer WKWebView instead!
    Feel free to PM me if you need help doing this!

    ~ Ry

  • EwoudvdWerfEwoudvdWerf USMember ✭✭✭

    @RyanDixon could you give me an example of a HybridWebView or is there also a third party webview i could use?

  • mshwfmshwf EGMember ✭✭✭

    I have a similar issue. I've posted a question https://forums.xamarin.com/discussion/141665/uiwebview-in-xamarin-ios-seems-to-ignore-external-css-styles
    if anyone could help!

  • JS_GJS_G USMember ✭✭

    Hi all,
    I'm new to Xamarin dev and developing app using WebViewClient and loading our application using HTTPS url.
    It is working fine on Android emulators and managed to produce APK file for Anroid.

    Please advise if WebViewClient app will work fine for IOS devices?


Sign In or Register to comment.