-2

How to load a local HTML page into WKWebview ?

I set allowingReadAccessTo to the directory containing all files. But still get an error.

   if let testTempUrl = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory:"sub") {
                if FileManager.default.fileExists(atPath: testTempUrl.path) {

                    webViewWK.loadFileURL(testTempUrl, allowingReadAccessTo: testTempUrl.deletingLastPathComponent())


                } else {
                    askSiriWhy()
                }
            }

The HTML page loads without problem if I use UIWebView instead of WKWebView.

martomstom
  • 593
  • 7
  • 18
  • 1
    You'll get a lot of down votes (not from me, though) until you show us what you've tried. It's the only way we can help you without doing it for you. – Mozahler Apr 28 '17 at 11:37

1 Answers1

1

I'm not sure why you're using "allowingReadAccessTo" - Where is your file located?

if FileManager.default.fileExists(atPath: testTempUrl.path) {

                    webViewWK.loadFileURL(testTempUrl, allowingReadAccessTo: testTempUrl.deletingLastPathComponent())

 }

why not just:

if FileManager.default.fileExists(atPath: testTempUrl.path) {
    webViewWK.loadFileURL(testTempUrl)
}
Mozahler
  • 4,958
  • 6
  • 36
  • 56