WKWebView Won't Load (NSViewController, OS X)

删除回忆录丶 提交于 2020-05-14 17:18:42

问题


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:

ScreenShot



来源:https://stackoverflow.com/questions/35462981/wkwebview-wont-load-nsviewcontroller-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!