I have an iOS app which part of logic is written in JavaScript
. I've created a WKWebView
where I load my initial .js
file, but when executed, it needs to read from other files from my local resources. The problem is I'm missing a concept of how do I achieve that.
I've tried loading each separate file one after another in Swift
into the webView
but it's too many files to load by hand.
I though, maybe there is a http server for Swift
that will have an access to project files. And I found solutions like this or this.
An approach looks great but even if I do so, I still can't access files and folders from my Xcode project structure. I've created a basic http server and also a DAV server, added GET
handlers, etc.
Maybe I'm doing something wrong with setting it up but at the end when I create an object of http server
, I can still access it from my webView
at http://192.168.0.11:8080
so for sure it's initialized properly and working.
Answering my question so it helps someone in the future. I've used at the end this library. And it looks like there was some configuration missing so the server serves all the pages and files dynamically. My code is:
When this configuration is done and the server is running on port of your choice (mine is
8080
), you simply open up your embedded browser inside the app (e.g.WKWebView
) and loadIf you simply always want to run
index.html
when connecting to/
of the http server, you can add this configuration beforehttpServer.start()
method:And now in
webView
just connect tohttp://localhost:8080
and the file you have given as aGCDWebServerResponse
will load.