7

I'm trying to load a WKWebView but my simulator (iPhone 6 - iOS 10.2) keeps displaying a blank screen. I can only see horizontal and vertical scrollers as if the webview was quite wide but empty.

App Transport Security Settings > Allow Arbitrary Loads is set to YES in the info.plist file.

Here is my code

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {

    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        let myURL = URL(string: "https://www.google.co.uk")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }

}

I tried several pieces of code found online or even downloaded working simple WKWebView xcodeproj, but I always have the same problem.

I can load the website (https://www.google.co.uk) in my browser. Also tried with general .com extension, or local .co.uk extension.

EDIT: works perfectly fine on the device but not on the simulator

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
romain64
  • 89
  • 9
  • I have the same problem. WKWebView does not work in the Simulator, but works on device. However, UIWebView works in the Simulator. OP of this thread said that it was the antivirus program causing it, I have BitDefender on my Mac. I wonder if that might cause issues. Do you also have BitDdefender? https://stackoverflow.com/questions/50291678/wkwebview-not-loading-webpage-renders-blank-screen-in-swift – Sajjon Nov 01 '18 at 12:12

2 Answers2

0

I know it's an old post but it might be helpful for others.

So it most have something to do with override loadView() This method loads or creates a view and assigns it to the view property, but somehow in Simulator it doesn't do what it should!

Try removing loadView and Add the method body inside viewDidLoad() and it should be fine.

Shahriyar
  • 520
  • 7
  • 18
0

Check if you have a proxy running. I've had Charles Proxy running in the background and that caused this issue.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223