iOS 12.2 WKWebview:加载https或http url后无法加载本地html页面

Nik*_*Nik 5 ios swift wkwebview

在启动应用程序时,我正在WKWebView中加载https://www.google.com。应用程序有一个按钮,单击该按钮后,应用程序将从文档目录加载本地html页面。我使用以下代码加载html页面。

let destPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,
                                                           .userDomainMask,
                                                           true)[0]
        let fileName = "Demo.html"
        let fullDestPath = URL(fileURLWithPath: destPath)
            .appendingPathComponent(fileName)
            self.webView! .loadFileURL(fullDestPath, allowingReadAccessTo: fullDestPath)
Run Code Online (Sandbox Code Playgroud)

该代码一直运行到iOS 12.1.4,但是在iOS 12.2中,它没有加载html页面并抛出错误

ProvisionalPageProxy::didFailProvisionalLoadForFrame: pageID = 1, frameID = 1, navigationID = 2
Run Code Online (Sandbox Code Playgroud)

Rac*_*wal 0

检查文档目录中是否存在文件Demo.html 。如果不存在,则不会加载 html 页面。

尝试从以下位置加载Bundle

if let path = Bundle.main.path(forResource: "Demo", ofType: "html") {
   let htmlURL = URL(fileURLWithPath: path)
       webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL)
 } else {
    print("File not found")
 }
Run Code Online (Sandbox Code Playgroud)