question

AnilKakar-6462 avatar image
0 Votes"
AnilKakar-6462 asked ·

Problems rendering HTML for iOS physical device when updating to WKWebView

When I'm attempting to render HTML in a WKWebView using a custom renderer in iOS, the CSS and images aren't rendered when I use;

 public void LoadUrl(string url)
 {
 var uri = new Uri(url);
 var safeHostUri = new Uri($"{uri.Scheme}://{uri.Authority}", UriKind.Absolute);
 var safeRelativeUri = new Uri($"{uri.PathAndQuery}{uri.Fragment}", UriKind.Relative);
 LoadRequest(new NSUrlRequest(new Uri(safeHostUri, safeRelativeUri)));
 }

or;

 public void LoadUrl(string url)
  {
  var stringHtml = File.ReadAllText(url, Encoding.UTF8);
  var baseUrl = Path.GetDirectoryName(url);
 LoadHtmlString(stringHtml, baseUrl == null ? new NSUrl(NSBundle.MainBundle.BundlePath, true) : new NSUrl(baseUrl, true));
  }


There is no problem in Android or in iOS emulators. Any help is greatly appreciated!












dotnet-xamarinformsdotnet-ios
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered ·

Welcome to Microsoft Q&A!

Try to use WKWebView.LoadFileUrl instead of LoadHtmlString() to access local html file.

Refer to https://stackoverflow.com/a/28676439/8187800.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][2] to enable e-mail notifications if you want to receive the related email notification for this thread.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.