iOS 无法从文档文件夹加载到 webView

Can't load from documents folder into webView on iOS

我试图从 iOS 上的文档文件夹中加载一些 html 和图像,但没有成功。谁能帮我理解为什么这段代码不起作用?

    let html = "<html><body><font size='20>oi</font></body></html>"
    let saveHTML = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("sample.html")
    try? html.data(using: .utf8)!.write(to: saveHTML)
    webView.load(URLRequest(url: saveHTML))

问题解决起来很简单,就是权限不够:

webView.loadFileURL(saveHTML, allowingReadAccessTo: saveHTML)