0

I have an HTML fragment which is taken from an outer database. It is not a local asset file.

On the other hand, I have 5-6 files of my own CSS and JS files which this HTML use.

I added those CSS and JS files by adding their parent directory:

File -> Add files to "MyProject"

The parent directory is called: web_assets

Then, I want to use these files in my WKWebView.

I tried this:

var myBundle = Bundle.main.bundleURL
myBundle.appendPathComponent("web_assets", isDirectory: true)
contentWKWebView.loadHTMLString(html, baseURL: myBundle)

This is not working.

Any idea?

AJ Gottes
  • 379
  • 1
  • 2
  • 14

1 Answers1

0

I found it on YouTube :-)

You use it like this:

Let's say you have a CSS file named file.css

let jsPath = Bundle.main.path(forResource: "web_assets/file", ofType: "css")!
let baseUrl = URL(fileURLWithPath: jsPath)
contentWKWebView.loadHTMLString(html, baseURL: baseUrl)

AJ

AJ Gottes
  • 379
  • 1
  • 2
  • 14