envoy / Embassy

Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux
MIT License
600 stars 74 forks source link

WKWebView freezes when I start the Embassy http server #69

Open josh83abc opened 5 years ago

josh83abc commented 5 years ago

Hi guys!

I'm an experienced developer but a beginner with Swift and iOS, so your help will be very valuable. My iOS app is based on a WKWebView loading some HTML (hybrid app).

Since the WKWebView cant access to local files, I wanted to run a HTTP server on the iOS device and then use it from inside the WKWebView.

However, when I start the Embassy server like in your example, my WKWebView becomes unresponsive and completely frozen. If I start a safari outside the app, I do see that the HTTP server is working. I also do see that it is the line "loop.runForever()" which freezes the webview.

How can I fix that? Maybe I missed something :)

Thanks a lot!! Josh

ChiChou commented 4 years ago

Don't use runForever in UI thread. You need DispatchQueue.global(qos: .background).async