2

I am trying to load an HTML file on WebView. The HTML contains image URLs. When I try to run that image URL on Web Browser, it works. The image gets displayed. But the same image does not get loaded in WebView in my app.

I found this question on Apple Developer Forum, it is still unanswered. Any help would be appreciated. Thanks

2 Answers 2

3

I faced a similar issue a few months ago, and I fixed it by replacing UIWebView with WKWebView.

WKWebView is the official replacement of UIWebView, take a look at its documentation:

Starting in iOS 8.0 and OS X 10.10, use WKWebView to add web content to your app. Do not use UIWebView or WebView.

Sign up to request clarification or add additional context in comments.

4 Comments

Hello, I am facing same issue with WKWebView also. Actually, the HTML I am using is the Page Source of some random webPage. If this can be the issue for images not getting displayed ?
The images that I stored locally in XCode are displayed in WebView. The issue is with images that are needed to fetch from URL in HTML.
This is weird. Using WKWebView was enough for me. Take a look at the discussion here, it may help you: stackoverflow.com/questions/39901982/…
In my case i tried first using webview but not loaded images it shows boxes instead of images. then i tried wkwebview it also not shown images.
2

Please try to fetch your images using WKWebView.

Step 1: import WebKit in your class

import WebKit

Step 2: Add WebKit delegate to your controller

class ViewController: UIViewController, WKUIDelegate

Step 3: create variable of WKWebView type

var webView: WKWebView!

Step 4: Configure WKWebView. Override loadView() function with following line of code

    let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView

Step 5: In viewDidLoad() pass URLRequest to webView()

let url = "your URL"
let request = URLRequest(url: url!)
webView.load(request)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.