问题
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.
回答1:
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:
来源:https://stackoverflow.com/questions/35462981/wkwebview-wont-load-nsviewcontroller-os-x