0

I am working on hybrid app which mostly runs in the WkWebView, but uses camera and so on. We also have completely native screen which also needs communication with backend. The customer’s wish is to run those requests via WKWebView (they don’t want to perform them natively). So we have NavigationController -> WkWebViewController -> FunctionalityViewController.

FunctionalityViewController has reference to the WkWebViewController via delegate to send requests through JavaScript to backend. The iOS communication works fluently (FunctionalityViewController -> WkWebViewController) and also calls to via debugging with Safari all calls reach WkWebView.

The WKWebView then issues requests to backend and they are executed sometimes, and sometimes not… but when the FunctionalityViewController is dismissed all the unexectured requests are issued - like the WkWebView queues them…

Does anyone know how to fix that? (I have two undesired solutions like making FunctionalityViewController childViewController and so on - but I would like to avoid that if possible). Any suggestions are welcome.

Leon Dobnik
  • 333
  • 1
  • 4
  • 10

1 Answers1

0

I have finally found out what's wrong. The WKWebView must be in the view hierarchy to work properly. There are certain bug reports on GitHub describing the same problem.

Source(1): Keeping a WKWebView and it's UIViewController in the background running and accessible from multiple ViewControllers Source(2): WKWebKit javascript execution when not attached to a view hierarchy Source(3): http://ileyf.cn.openradar.appspot.com/43038986

For downvoters: is that all you can do right?

Leon Dobnik
  • 333
  • 1
  • 4
  • 10