I am using WKWebView for my IOS app but in the app its not loading images for the slider on the site. In the code I have also managed to get javascript working, which is working as the other menu items and other jquery scripts are running fine. It just seems that the slider images wont load. Also when I am trying to search on the search bar on the webview its auto loading the text but the images are not loading with the autoload. On the website all of it is loading just fine. I guess I am missing something. Please excuse my amature question here.
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
let webView: WKWebView = {
let prefs = WKWebpagePreferences()
prefs.allowsContentJavaScript = true
let configuration = WKWebViewConfiguration()
configuration.defaultWebpagePreferences = prefs
let webView = WKWebView(frame: .zero, configuration: configuration)
return webView
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.addSubview(webView)
guard let url = URL(string: "https://gopalmone.com")else{
return
}
webView.load(URLRequest(url: url))
DispatchQueue.main.asyncAfter(deadline: .now() 5){
self.webView.evaluateJavaScript("document.body.innerHTML"){result, error in
guard let html = result as? String, error == nil else{
return
}
print(html);
}
}
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
webView.frame = view.bounds
}
}
CodePudding user response:
Add following key into info.plist if not added
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>