faris97
faris97

Reputation: 402

(Swift) How to present HTML in WebView

When I try to load url everything works fine. I also tried to load normal HTML and that worked fine too.
But this html I got from API is so weird and without tags. Is it possible to somehow present this in webView? This is how my HTML looks like:
enter image description here

Code to load it :

var html: String
html = cards[Int(slider.value)-1].content
print(html)
webView.loadHTMLString(html, baseURL: nil)

Upvotes: 0

Views: 208

Answers (1)

dirkgroten
dirkgroten

Reputation: 20682

The API is returning the data URL-encoded. So you have two options:

  • Preferred: Try fetching the data non URL-encoded. Maybe by passing the accept header "text/html", assuming the API might default to "text/plain". Check the API documentation and your request headers.
  • As a fallback: Use NSString.removingPercentEncoding.

Upvotes: 2

Related Questions