fishbone
fishbone

Reputation: 3249

Can't connect to local web server in my cordova iOS app

When switching from UIWebView to WKWebView in a Cordova iOS app there are common known problems with same origin policy when loading a web app from the local file system.

The typical fix is to use a local web server (listening on localhost) which serves your HTML,CSS,JS.

This is why I tried to switch to this cordova plugin: https://github.com/apache/cordova-plugins/tree/wkwebview-engine-localhost

Unfortunately the result is a blank screen. In the web debug console I called

console.log(location.href)

which returns about:blank. Then I tryed navigating to the local web server with this JS call from the console:

location.href = 'http://localhost:8080';

But the web view stays at about:blank. I also tried with different ports and of course I checked my config.xml (e.g. <allow-navigation href="*" />)

I assumed that there is a problem with with the plugin so I switched to Ionic Webview. Interestingly it has the exact same behavior.

In general I am able to navigate to other sites, but not to localhost:[port], so I guess that those plugins are not able to start the web server at all. However, I couldn't find anyone else with this problem.

What could be the reason for this problem? Is there a way to debug this? Unfortunately my web console doesn't report any problems.

Upvotes: 0

Views: 683

Answers (1)

fishbone
fishbone

Reputation: 3249

The problem here was not to start the web server but connecting to it. The communication has been prevented by VPN (MobileIron) which tries to tunnel those connections. Unfortunately, at the moment there is no solution for WkWebView at all.

Upvotes: 1

Related Questions