Reputation: 1583
First, this is for Swift 3. I am creating a container app that simply serves a website.
The problem is that everything comes back fine and works, but the images are not showing. When debugging, it looks like the problem is that the webview isn't accepting images from an asp app site that uses a relative path to hit a .net api endpoint within the app. The image is served with the following tag:
<img src="api/Answers/Image/1006" class="panel-image" alt="">
All other functionality and data is coming back fine. The website works perfectly fine on all standard web browsers including safari. Any ideas on how to fix this.
Upvotes: 0
Views: 336
Reputation: 1583
Allen's answer was insightful on another nature of setting up a source, but I found that the back end developer for the site accidentally set the image api to require authentication. The odd thing is that this authentication didn't trigger on any device other than the ipad app. Even the browser didn't request authentication. Removing authentication on the image api fixed the problem.
Upvotes: 0
Reputation: 1202
You would think the webview would understand how to handle a relative url for an img tag... Adding protocol and host of the path to the api should solve your problem though.
If you are injecting the HTML, try something along the lines of this:
'<img src='window.location.protocol + '//' + window.location.host + '"/api/Answers/Image/1006" class="panel-image" alt="">'
Or... if you are setting it via id:
var img = document.getElementById("ImageId");
img.src = window.location.protocol + '//' + window.location.host + '/api/Answers/Image/1006';
Upvotes: 1