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.
Thanks for contributing :)
Finally after spending hours on this , Here i found the solution for this common Webview "frame load interrupted" issue:
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!)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With