0

Can anyone explain how to load local html file to WKWebView?

I tried with the below code works well in simulator but not on device

 let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
 let documentDirectoryPath: String = path[0]
 let fileManager = FileManager()

 let destinationURLForFile = URL(fileURLWithPath: documentDirectoryPath + "/" + "\(NameF.fileName)/\(NameF.Languages)/page_\(i + 1 ).html")
 print("D2\(destinationURLForFile)")
 let request = NSURLRequest(url: destinationURLForFile)
 webView!.load(request as URLRequest)

Any suggestions would be helpful!

Daniyar
  • 2,975
  • 2
  • 26
  • 39
Raghuram
  • 1,651
  • 2
  • 12
  • 17

1 Answers1

0

Thank you for your response guys and for who tried my question.Finally found the answer by opening the local file and read its content and then send that string into a WKWebview

And the piece of code is

 do{
            let fileName =  try String(contentsOf: destinationURLForFile)
            print("fileName is equal to\(fileName)")
            webView.loadHTMLString(fileName, baseURL: destinationURLForFile)


        }catch{

        }
Raghuram
  • 1,651
  • 2
  • 12
  • 17