WKWebView未加载网页-在Swift中呈现空白屏幕 [英] WKWebView not loading webpage - renders blank screen in Swift

查看:565
本文介绍了WKWebView未加载网页-在Swift中呈现空白屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该代码应加载Apple主页,但显示空白屏幕.
HTTP和HTTPS URL都会发生这种情况.

This code is supposed to load the Apple homepage, but instead shows a blank screen.
This happens with both HTTP and HTTPS URLs.

代码:

import UIKit
import WebKit

class WebViewController: UIViewController, WKUIDelegate{

    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView

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

        view.backgroundColor = .red

        let myURL = URL(string: "https://www.apple.com")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }
}

我尝试更改应用程序传输安全设置"以允许任意加载.没有任何改变.

I have tried changing 'App Transport Security Settings' to allow arbitrary load. Didn't change anything.

屏幕截图:

视图层次结构:

模拟器的Safari调试控制台:

Safari debug console for the simulator:

推荐答案

我找到了解决方案.该问题是由AVG AntiVirus的Webshield引起的.由于某些原因,AVG Webshield会将来自模拟器的所有网络通信视为欺诈. 以下屏幕快照显示了在模拟器上运行的safari应用程序.它说www.apple.com是不安全的或任何其他网站.

I have found the solution. The problem was being caused by AVG AntiVirus's webshield. For some reason AVG webshield treats all network communication from the simulator as fraudulent. The following screenshot shows the safari app running on simulator. It says that www.apple.com is not safe or any other website.

以下屏幕截图来自system.log,显示了webkit的错误.

The following screenshot is from system.log showing errors with webkit.

您可以通过安装AVG防病毒程序并打开webshield来复制此问题.应用程序中的WKWebview(在模拟器上)不会加载任何内容.

You can replicate this problem by installing AVG antivirus and turning on the webshield. WKWebview in your App(On the simulator) wouldn't load anything.

我不明白为什么它不能在实际设备上正常工作.该设备可能是另一个问题.我还删除了派生数据文件夹,即实际的应用程序,并重新启动了设备.

I don't understand why it wasn't working on an actual device tho. It could have been another problem with the device. I also deleted the derived data folder, the actual app and had restarted the device.

谢谢大家的回答和帮助.

Thank you everybody for the answers and help.

这篇关于WKWebView未加载网页-在Swift中呈现空白屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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