Reputation: 7256
In my app, I load local files with the file://
protocol in a UIWebView
. I do however also load several http://
protocol resources in those files, which in turn load other resources, but rather than using a specific protocol relying on the //
protocol (Protocol Relative URL) to use the appropriate protocol, which should be either http://
or https://
, but which ends up being file://
in my case.
I have been tinkering around this for a while now, trying to replace all //
links with http://
through javascript, unsuccessfully, and I'm pretty lost. I can't change the code that requests the //
links, and iOS/Webkit automatically assumes that file:// is the right protocol to use.
Is there a way around this, making iOS always use http://
in place of //
, or any other way that would work?
Upvotes: 0
Views: 1395
Reputation: 7256
After looking over it again, I realised I didn't really need to use the file-protocol at all – I simply get the HTML from the local file, input that into the UIWebView
using loadHTMLString: baseURL:
, and set the baseURL
to http://domain.com
. That way, the protocol used is HTTP.
This solution did involve quite some tinkering with the webView:shouldStartLoadWithRequest:navigationType:
and back/forward history changes, but it is nothing compared to trying to change the protocols.
If anyone has other solutions, I'm very interested to see them!
Upvotes: 1