Re: WKWebView does not load images

Steve Christensen

A couple of things I notice:

1. You seem to be trying several variants on the base or full file URLs without success. Are you generating the paths via NSURL so that they are formatted correctly?

baseURL = [NSURL fileURLWithPath:@"/absolut/path/to/PicturesFolder" isDirectory:YES];

This URL could be passed to -loadHTMLString:baseURL: or you could use baseURL.absoluteString when generating the <base href…>.

2. If your PicturesFolder is contained within a directory in one of the known domains, are you using NSSearchPathForDirectoriesInDomains() to generate that portion of the base URL path and then appending subdirectory components using -stringByAppendingPathComponent: repeatedly to build the full path? If you are making an assumption about where those folders are created then that could be biting you if you made the wrong assumption.

3. The <img> src of "./image67.gif" looks weird to me. I would expect that "image67.gif" would work since the base URL already provides the partial URL to the directory containing that image.

On Oct 7, 2017, at 12:34 AM, Gerriet M. Denkmann <g@...> wrote:

On 7 Oct 2017, at 03:52, Steve Christensen <punster@...> wrote:

Is /path/to/myImage.gif a full path or a partial path? I ask because you didn’t specify a base URL.

htmlString actually looks like:

<base href=“file:/absolut/path/to/PicturesFolder/“ />

<img alt=“alternate”  src=“./image67.gif" />

I also tried (following the suggestion from Jens):
<img alt=“alternate”  src=“file:///absolut/path/to/PicturesFolder/image67.gif” />
Still no picture.

Do the path components have the correct case if the image is on a case-sensitive volume?
Yes, they have. And yes, the volume is case-sensitive.

Also, both:
[ self.webView loadHTMLString: htmlString  baseURL: nil ];
[ self.webView loadHTMLString: htmlString  baseURL:  urlTo “/“  ];
give the same result.

On Oct 6, 2017, at 7:58 AM, Gerriet M. Denkmann <g@...> wrote:

[ wkWebView loadHTMLString: htmlString  baseURL: nil ];

htmlString contains: …<img alt=“alternate”  src=“/path/to/myImage.gif” /> ….

WKWebView just shows a rectangle containing: “alternate”.

WebView shows the picture.

Are there any special steps needed to make WKWebView show images?


Join to automatically receive all group messages.