Ios wkwebview无法从documentsURL加载基本url

Ios wkwebview无法从documentsURL加载基本url,ios,swift,xcode,wkwebview,Ios,Swift,Xcode,Wkwebview,Webkit从.documentsURL html网页加载,iOS设备不显示图像、js、css文件,在模拟器上运行良好。我写的代码中有什么bug let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] let documentsURL = URL(fileURLWithPath: documentsPath, isDirectory:

Webkit
从.documentsURL html网页加载,iOS设备不显示图像、js、css文件,在模拟器上运行良好。我写的代码中有什么bug

let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        let documentsURL = URL(fileURLWithPath: documentsPath, isDirectory: true)

        let urltostr = documentsURL.absoluteString
        //print(urltostr)
        let htmlurl = urltostr+"0/index.html"
        let finalURL = URL(string: htmlurl)
        let base = urltostr+"0/"
        let baseUrl = URL(string: base)
        //let baseUrl = URL(fileURLWithPath: base, isDirectory: true)
        do {
            let fileName  = try String(contentsOf: finalURL!)
            webview.loadHTMLString(fileName as String, baseURL: baseUrl)
        } catch {
            // catch error
            print("Error web view get html")
        }

就连我也面临着同样的问题。你找到解决办法了吗?是的,我找到了!,加载html字符串时,必须将访问权限设置为读取webview.loadFileURL(finalURL!,allowingReadAccessTo:documentsURL)