gpt4 book ai didi

arrays - WebKitView请求没有通过?

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

我正在尝试发出Webkit请求,但我的Webview却返回零。 imageDownload文档存储在我的应用程序本地。

    (lldb) po req
▿ imageDownload.svg
▿ url : Optional<URL>
▿ some : imageDownload.svg
- _url : imageDownload.svg
- cachePolicy : 0
- timeoutInterval : 60.0
- mainDocumentURL : nil
- networkServiceType : __C.NSURLRequestNetworkServiceType
- allowsCellularAccess : true
▿ httpMethod : Optional<String>
- some : "GET"
- allHTTPHeaderFields : nil
- httpBody : nil
- httpBodyStream : nil
- httpShouldHandleCookies : true
- httpShouldUsePipelining : false

(lldb) po fileURL
▿ imageDownload.svg
- _url : imageDownload.svg


这是控制台结果,下面是我尝试设置Webview的方式

    override func viewDidLoad() {
// let req = URL(string: itemDownload[0]!)
let fileURL:URL = URL(string: itemDownload[0]!)!
let req = URLRequest(url: fileURL)
self.svgView.load(req)
super.viewDidLoad()
// Do any additional setup after loading the view.
}


我也尝试过

override func viewDidLoad() {
super.viewDidLoad()
let path = Bundle.main.path(forResource: itemDownload[0], ofType: "svg")
if path != "" {
let fileURL:URL = URL(string: itemDownload[0]!)!
let req = URLRequest(url: fileURL)
self.svgView.load(req)
}
}


我不确定为什么即使控制台中有值,它也没有显示指定的SVG文件。

最佳答案

我的文件位置恢复为零,因此我将代码更改为此

if let svgPath = Bundle.main.path(forResource: itemDownload[0], ofType: nil), FileManager.default.fileExists(atPath: svgPath){
let fileURL:URL = URL(fileURLWithPath: svgPath)
let req = URLRequest(url: fileURL)
self.svgView.load(req)
}


现在就可以了!

关于arrays - WebKitView请求没有通过?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58140025/

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