【问题标题】:WKWebview showing blank page when trying to load local web. How to print errors in console?WKWebview 在尝试加载本地 Web 时显示空白页面。如何在控制台中打印错误?
【发布时间】:2020-12-03 11:14:46
【问题描述】:

我正在尝试加载本地网站,但无法正常工作,只显示白屏。

let zipName = webSection?.zipResource?.zipName?.lowercased() {
let zipPath = ProjectPath.path.appending(zipName.deletingPathExtension).appending(pathComponent: "index.html")
let url = URL(fileURLWithPath: zipPath)
//webView.loadFileURL(url, allowingReadAccessTo: url) //suppossedly new method for loading local websites, but it haves same behaviour, blank screen
webView.load(URLRequest(url: url))

在 Android 中,我可以在 logcat 中看到没有显示内容时生成 web 视图的错误,但在 Xcode 中,我在控制台中什么也看不到。我怎样才能看到 WKWebView 出现了哪些错误?

【问题讨论】:

    标签: ios swift xcode wkwebview


    【解决方案1】:

    在 viewDidLoad 中实现 webView 导航委托

    self.webView.navigationDelegate = self
    
    extension ViewController : WKNavigationDelegate {
        func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
            print(error.localizedDescription)
        }
    }
    

    【讨论】:

    • 已经尝试过了,没有发生,没有打印出来
    • 你在viewDidLoad中实现navigationDelegate了吗?
    • 是的@agha Shahriyar,我做到了:webView.navigationDelegate = self there
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    相关资源
    最近更新 更多