Arj*_*tir 11 objective-c ios swift
在 WebView 中显示 pdf 时出错
“错误域=WebKitErrorDomain 代码=102”帧加载中断”
但是使用相同的代码图像正确填充。
感谢您的贡献:)
最后在花了几个小时之后,在这里我找到了这个常见的 Webview “帧加载中断”问题的解决方案:
尝试以下代码进行上述步骤
//在Web视图中显示文档的方法
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
}
}
})
}
Run Code Online (Sandbox Code Playgroud)
//本地存储数据的方法
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!)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6347 次 |
| 最近记录: |