0

I'm implementing an WKWebView but when there is an issue with the network such slow network connection the WKWebView loads blank page. Here is my implementation:

func loadWebView() {
    if let url = URL(string: self.urlLbl.stringValue){
        let request  = URLRequest.init(url: url)
        let config = WKWebViewConfiguration()
        self.webView = WKWebView(frame: self.customView.frame)
        self.webView.navigationDelegate = self
        self.webView.frame = customView.bounds
        self.webView.autoresizingMask = [.width, .height]
        self.webView.wantsLayer = true
        self.webView.customUserAgent = userAgentStr
        self.webView.load(request)
        self.webView.layer?.backgroundColor = NSColor.green.cgColor

        self.view.needsDisplay = true
        self.webView.load(request)
        webView.allowsBackForwardNavigationGestures = true
        self.customView.addSubview(self.webView)

    }
}

My question to you guys there is a way to know if the request load and if didn't there is a way to reload the request?

I'll really appreciate your help

user2924482
  • 6,844
  • 16
  • 65
  • 133
  • 1
    You're loading the request twice, which is likely to cause trouble. I also recommend adding the view to its superview before you load the request (may not matter, but I would still do it in that order). You're also setting the frame wo webView to `customView.frame`, but I'm pretty certain you mean `customView.bounds`. You may get away with using `.frame` there, but I wouldn't rely on that. – Rob Napier May 02 '19 at 19:32
  • @RobNapier, That is not the issue. The issue is the when the network is slow the the WebView is load black page. – user2924482 May 02 '19 at 19:38
  • The delegate will receive a message (`webView(_:didFail:withError:)`) if there is a failure. – Rob Napier May 02 '19 at 19:46
  • @RobNapier, the connection slow there is no error even this function it never gets call `webView(_ webView: WKWebView, didCommit navigation: WKNavigation!)` – user2924482 May 02 '19 at 19:55
  • `didCommit` occurs when you start receiving data. You're probably thining about `didStartProvisionalNavigation`. You can also check `didFailProvisionalNavigation`, but I'd still start by getting rid of the double-load. – Rob Napier May 02 '19 at 20:11
  • @RobNapier didFailProvisionalNavigation it gets call and I was able to reload the page after that. Thank you – user2924482 May 02 '19 at 20:37

0 Answers0