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
8
  • 1
    see this stackoverflow.com/questions/6420925/… Commented Apr 21, 2017 at 4:55
  • i can get data from sqlite database in String formate . i have no html file. database and image folder download every time when user login and put in document folder . Commented Apr 21, 2017 at 5:13
  • @HarshilKotecha In string format means the URL like Documents/datadb/DestinationGuide/Images/Destination-Guide.png, right ? Commented Apr 21, 2017 at 5:16
  • no i can get full html code in string formate not only URL Commented Apr 21, 2017 at 5:17
  • when i pass html after print Log output like this . <img src=\"/Documents/datadb/DestinationGuide/Images/[email protected]\" alt=\"\" /> Commented Apr 21, 2017 at 5:39

1 Answer 1

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))
Sign up to request clarification or add additional context in comments.

1 Comment

i also thinking like this just a minute i test this one :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.