Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView Won't Load (NSViewController, OS X)

I am trying to build a simple WKWebView application that will display Google in the WebView. The app works perfectly fine; however, upon implementing the WKWebView, the app no longer shows a window. It just simply launches the app (in the dock) with no NSView in sight.

ViewController.swift

import Cocoa
import WebKit

class ViewController: NSViewController {

    var webView: WKWebView?

    override func loadView() {
        self.webView = WKWebView()
        self.view = self.webView!

        let url = NSURL(string:"http://www.google.com/")
        let req = NSURLRequest(URL: url!)
        self.webView!.loadRequest(req)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }
    }


}

There doesn't seem to be any further examples online, nor does there seem to be any projects on GitHub.

Thanks. I haven't come across this before.

like image 756
Justin Bush Avatar asked Feb 17 '16 16:02

Justin Bush


1 Answers

I guess there're some limitations behind Xcode Settings those hidden settings make your WKWebView NOT WORK!!!

You could try these ways, Maybe you will find the solution:

1) Search these key words by Google, You'll find some tutorials:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

2) Check your Project Setting panel. Make sure you've CHECKED the NetWork [Incoming] & [OutComing] item:

ScreenShot

like image 174
Corxit Sun Avatar answered Sep 18 '22 08:09

Corxit Sun