Load edited local file in WKWebView



I’m trying to load a local html file where I just saved some changes to in a WKWebView. I used to do it with loadHTMLString(), but unfortunatly there seems to be no way to enable back/forward swipe gestures using loadHTMLString().


Writing to the file works just fine, but I can’t seem to load the edited file. I keep getting the original. Anyone know what I’m doing wrong here?




let file = "localFile.html"

        let text = "Some changes"

        if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {

            let fileURL = dir.appendingPathComponent(file)

            do {
                try text.write(to: fileURL, atomically: false, encoding: .utf8)
            catch {/* error handling here */}

            do {
                let loadedText = try String(contentsOf: fileURL, encoding: .utf8)
                print(loadedText) // checking saved text
                let url = URL(fileURLWithPath: Bundle.main.path(forResource: "localFile", ofType: ".html")!)
                let request = URLRequest(url: url)

            catch {/* error handling here */}

Powered by WPeMatico

You may also like...

Comments are closed.