gpt4 book ai didi

ios - 错误域=WebKitErrorDomain 代码=102 "Frame load interrupted"

转载 作者:行者123 更新时间:2023-12-02 00:13:25 34 4
gpt4 key购买 nike

在 WebView 中显示 pdf 时出现错误

“Error Domain=WebKitErrorDomain Code=102“帧加载中断”

但是使用相同的代码图像可以正确填充。

最佳答案

感谢您的贡献:)

最后,在花了几个小时之后,我在这里找到了这个常见 Webview “框架加载中断” 问题的解决方案:

  • 以字节形式下载文件
  • 将其存储在本地存储中
  • 使用本地路径在 Web View 中加载文件并且可以正常工作

尝试使用以下代码执行上述步骤

//在Web View 中显示文档的方法

    func methodToShowDocumentInWebView(strUrl : String, fileName :  String, controller: UIViewController)  {

//Get Request to download in bytes
Service.shared()?.callAPI(withURLWithoutHandlingAndLoaderAndHttpStatusCode: strUrl, andLoaderenabled: true, method: "GET", parameters: [:], withController: self, completion: { (data, error, code) in

if let dataFile = data {

let (success , payslipPath) = self.methodToWriteFileLocally(data: dataFile as! Data, fileName: fileName, directory: "Leave")
if success {
webviewInstance.loadRequest(NSURLRequest(URL: NSURL(string: payslipPath)!))
}else{
//Handle Error case
}
}
})
}

//本地存储数据的方法

func methodToWriteFileLocally(data : Data, fileName: String, directory : String) -> (success :Bool ,path :URL?) {

let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
let fileURL = documentsURL?.appendingPathComponent(directory)
let payslipPath = fileURL?.appendingPathComponent(fileName)

if !FileManager.default.fileExists(atPath: payslipPath!.path) {
do{
try FileManager.default.createDirectory(atPath: fileURL!.path, withIntermediateDirectories: true, attributes: nil)
}
catch{
//Handle Catch
return (false, nil)

}
let writeSuccess = (data as AnyObject).write(to: payslipPath!, atomically: true)
return (writeSuccess, payslipPath!)
}
else
{
let writeSuccess = (data as AnyObject).write(to: payslipPath!, atomically: true)
return (writeSuccess, payslipPath!)

}
}

关于ios - 错误域=WebKitErrorDomain 代码=102 "Frame load interrupted",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59189633/

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