7
votes

On application launch i am loading https://www.google.com in WKWebView. App has one button, on click of that button app is loading local html page from document directory. i used following code to load html page.

let destPath = NSSearchPathForDirectoriesInDomains(.documentDirectory,
                                                           .userDomainMask,
                                                           true)[0]
        let fileName = "Demo.html"
        let fullDestPath = URL(fileURLWithPath: destPath)
            .appendingPathComponent(fileName)
            self.webView! .loadFileURL(fullDestPath, allowingReadAccessTo: fullDestPath)

The code was working till iOS 12.1.4 however in iOS 12.2 it is not loading html page and throwing error

ProvisionalPageProxy::didFailProvisionalLoadForFrame: pageID = 1, frameID = 1, navigationID = 2
1
I am having the same issue atm. Did you find a solution for it? If the current page is an online resource I have the same problem, that a local resource won't load. - Dion
Same here. Any solution for this? It works when loading local file at app launch, but does not load when clicking a button that then loads the local file. Only happens iOS 12.2-12.4. - ryanrr
I am facing this issue on iOS 14.1, any solution? - Rohit Kale
It is not issue, it is security, cross domain redirection not allowed, you can try two options, 1. Load empty html file and then local file. 2. Use two different browser instances for local and web - Nik

1 Answers

0
votes

Check if the file Demo.html is present in the document directory. If is not present, then it will not load html page.

Try to load from Bundle

if let path = Bundle.main.path(forResource: "Demo", ofType: "html") {
   let htmlURL = URL(fileURLWithPath: path)
       webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL)
 } else {
    print("File not found")
 }