1

i can get html data from sqlite database .

let html = "<htmll>
...
...
<img src="Documents/datadb/DestinationGuide/Images/Destination-Guide.png">
...
</html>"
 webView.loadHTMLString(html, baseURL: nil)

Image store in this path

Documents/datadb/DestinationGuide/Images/Destination-Guide.png

It can not load in webview.

I think i want to give full path like application name after add this .

How to scan html code and replace src and href

Already try this :

~/Documents/datadb/DestinationGuide/Images/Destination-Guide.png
/Documents/datadb/DestinationGuide/Images/Destination-Guide.png
/DestinationGuide/Images/Destination-Guide.png
/DestinationGuide/Images/Destination-Guide.png
Harshil Kotecha
  • 2,846
  • 4
  • 27
  • 41

1 Answers1

3

You can save this html at DocumentDirectory as HTML file and then load that file webView. Try something like this way.

let html = "<html><img src=\"datadb/DestinationGuide/Images/Destination-Guide.png\"/> </html>"
//Save this html in `DocumentDirectory`
let saveHTML = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("sample.html")
try? html.data(using: .utf8)!.write(to: saveHTML)
//Now load this `sample.html` file in webView
webView.loadRequest(URLRequest(url: saveHTML))
Nirav D
  • 71,513
  • 12
  • 161
  • 183