gpt4 book ai didi

swift - 如何在iOS Swift的iframe中加载本地目录?

转载 作者:行者123 更新时间:2023-11-30 10:24:11 25 4
gpt4 key购买 nike

在loadHTMLStringImage函数中,我已经加载了index.html

let htmlPath = Bundle.main.path(forResource: "index", ofType: "html")
let htmlUrl = URL(fileURLWithPath: htmlPath!, isDirectory: false)
self.webView.loadFileURL(htmlUrl, allowingReadAccessTo: htmlUrl)


加载后,我一直在检查md5字符串。从md5压缩文件中,我将解压缩到本地目录并获得本地文件目录URL。并将本地目录URL传递给iframe src。但它显示为空白屏幕。

在控制台中,它显示:

Received an unexpected URL from the web process: 'file:///var/mobile/Containers/Data/Application/CECB33DC-8DE8-4FB0-BD28-73D46B47CB7C/Documents/appday/gng/v0-8/build/index.html'
2020-02-11 16:55:53.659227+0530 appday[15903:3679464] [Process] 0x10791c018 - WebPageProxy::Ignoring request to load this main resource because it is outside the sandbox


在viewDidLoad中,我也有WKPreference:

webView.navigationDelegate = self
webView.uiDelegate = self
webView.allowsBackForwardNavigationGestures = true

webView.configuration.preferences.javaScriptEnabled = true
webView.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")


在这里,我正在将本地目录URL加载到iframe src。 df是解压缩的文件本地目录URL路径:

我的URL路径如下所示:

'file:///var/mobile/Containers/Data/Application/CECB33DC-8DE8-4FB0-BD28-73D46B47CB7C/Documents/appday/gng/v0-8/build/index.html'


let url_path = df.absoluteString
let setPath = url_path

let js = "setFrame('" + setPath)
print("js::\(js)")


在这里,我尝试将本地文件目录URL加载到iframe src。

这是我在其中加载iframe src的本地index.html文件javascript:

 <iframe id='formFrame' src="" width="100%" height="100%" frameborder="0" scrolling="yes" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>

function setFrame(url) {
document.getElementById('formFrame').src = url;


}

[注意:我是来自本地目录URL的iframe内容未加载到本地HTML文件中]

任何帮助非常感谢...

最佳答案

import UIKit
import WebKit

class EventWallVC: UIViewController {

let directoryName : String = "appday/gng/v0-8/build"
//MARK: - IBOutlet
@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var lblEventWall: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
SVProgressHUD.show()
self.webView.navigationDelegate = self

var indexfileurl = URL(string: "")
let path = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent("\(directoryName)/\(index.html)")
indexfileurl = URL(fileURLWithPath: path)

//let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "")! /* your local bundle in save index.html file to get this */
self.webView.loadFileURL(indexfileurl, allowingReadAccessTo: indexfileurl)
let request = URLRequest(url: indexfileurl)
self.webView.load(request)

}
}

extension EventWallVC: WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
SVProgressHUD.dismiss()

}
}

关于swift - 如何在iOS Swift的iframe中加载本地目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60168084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com