ios - iOS 12.2 WKWebview:加载 https 或 http url 后无法加载本地 html 页面
问题描述
在应用程序启动时,我正在 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)
该代码一直工作到 iOS 12.1.4 但是在 iOS 12.2 中它没有加载 html 页面并抛出错误
ProvisionalPageProxy::didFailProvisionalLoadForFrame: pageID = 1, frameID = 1, navigationID = 2
解决方案
检查文件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")
}
推荐阅读
- qt - qtRunLoggedCommand 在哪里定义?
- vue.js - 带有 BootstrapVue 可编辑表格行的 VeeValidate
- android - 如何解决资源文件中的标识符预期错误
- arrays - 将一个数组的值与另一个数组相加
- c# - 无法在修改后的 C1 CMS 上添加或修改数据类型
- continuous-integration - Gitlab runner 上的 kubectl 凭证错误
- java - 我的 Minecraft 插件有问题吗?
- android - 从 API 获取图像并存储到房间数据库中
- vue.js - vue中的条件包装器渲染
- odoo-13 - OSError:找不到文件 Odoo 13