Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web view is blank after creating the bridge object #416

Closed
visgotti opened this issue Jun 19, 2021 · 1 comment
Closed

Web view is blank after creating the bridge object #416

visgotti opened this issue Jun 19, 2021 · 1 comment

Comments

@visgotti
Copy link

import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
    var mainWebView : WKWebView = WKWebView.init();
    override func viewDidLoad() {
          super.viewDidLoad()
          mainWebView.frame = view.frame;
          self.view.addSubview(mainWebView)
    }
    override func viewWillAppear(_ animated: Bool) {
         var bridge = WKWebViewJavascriptBridge.init(for: mainWebView);
         let url = URL(string: "http://127.0.0.1:8283")!
         mainWebView.load(URLRequest(url: url))
    }
}

When I comment out WKWebViewJavascriptBridge.init(for: mainWebView); the web page loads fine, otherwise it is a blank white screen. Any ideas why?

@visgotti
Copy link
Author

Closing.. here's what worked.

import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
    var mainWebView : WKWebView = WKWebView.init();
    var bridge : WKWebViewJavascriptBridge!;
    override func viewWillAppear(_ animated: Bool) {
        mainWebView.frame = self.view.frame;
        mainWebView.navigationDelegate = self;
        bridge = WKWebViewJavascriptBridge( for: mainWebView)!;
        bridge!.setWebViewDelegate(self);
        let url = URL(string: "http://127.0.0.1:8283")!
        mainWebView.load(URLRequest(url: url))
    }
    
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        bridge!.setWebViewDelegate(self);
        self.view.addSubview(mainWebView)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant