Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

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

Getting an error while showing pdf in WebView

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

But with the same code image is populating correctly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks for contributing :)

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

  • Download the file in bytes form
  • Store it in the Local Storage
  • Load the file in Web view with the local path and it works

Try the below code for the above steps

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

   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...