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

标签 ios objective-c swift

在 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/

相关文章:

ios - 每次进行更改时预览都会出错 (SwiftUI)

objective-c - NSScrollView 内的 NSTextView 不滚动 :(

iphone - Game Center 对接会 GKTurnBasedMatch 有明显滞后(约 1 分钟)

cocoa - Swift:如何将 AVPlayerLayer 添加到 NSView 的后层

ios - map 以北指向北极始终为 : programatically ios

iphone - iOS 应用程序和 Windows 身份验证

c# - 如何编写不同平台的应用程序? Linux、Mac、Windows 和移动平台

javascript - 如何通过 WebView 将来自 javascript 的 Alert() 操作接收到 Cocoa 应用程序

swift - 选择自定义单元格会激活另一个单元格

ios - 使 SwiftyUserDefaults 数组可供 iOS 和 watchOS 应用程序访问