WKWebView无法加载(NSViewController,OS X) [英] WKWebView Won't Load (NSViewController, OS X)

查看:149
本文介绍了WKWebView无法加载(NSViewController,OS X)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个简单的WKWebView应用程序,该应用程序将在WebView中显示Google.该应用程序运行正常;但是,在实现WKWebView之后,该应用将不再显示窗口.它只是在看不到NSView的情况下(在扩展坞中)启动应用程序.

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.
        }
    }


}

似乎没有更多的在线示例,或者GitHub上也没有任何项目.

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.

推荐答案

我想Xcode设置背后有一些限制,那些隐藏的设置使您的WKWebView无法正常工作!

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)通过Google搜索这些关键词,您将找到一些教程:

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

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

2)检查项目设置"面板.确保已检查NetWork [Incoming]& [即将推出]项目:

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

这篇关于WKWebView无法加载(NSViewController,OS X)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆