本文介绍了错误域= WebKitErrorDomain代码= 102“帧加载中断".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WebView中显示pdf时出错

Getting an error while showing pdf in WebView

错误域= WebKitErrorDomain代码= 102"帧加载中断"

"Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted"

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

But with the same code image is populating correctly.

推荐答案

感谢您的贡献:)

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

Finally after spending hours on this , Here i found the solution for this common Webview "frame load interrupted" issue:

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

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

Try the below code for the above steps

//在Web视图中显示文档的方法

//Method to Show Document In 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
             }
          }
       })
    }

//本地存储数据的方法

//Method to Store data Locally

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!)

   }
}

这篇关于错误域= WebKitErrorDomain代码= 102“帧加载中断".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:40
查看更多