This is how I load my wkwebview:
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "webviews/helloworld", ofType: "html")!)
self.webview!.loadFileURL(url, allowingReadAccessTo: url)
All is fine on the simulator but when try the app on my iPhone the downloaded images saved in the documents directory are not loaded.
This is how I get the file url of the image.
let fileManager = FileManager.default
let directoryURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
let pathComponent = filename
return directoryURL.appendingPathComponent(pathComponent).absoluteString
This would return something like this: file:///Users/Joshua/Library/Developer/CoreSimulator/Devices/9FE87399-6EBD-4DF3-BC6A-FD844DF62833/data/Containers/Data/Application/C1E250A4-823E-4590-8BDE-3891666CA728/Documents/57a8dd7255723c964658262d43c169c1
I have the same problem as this guy: WKwebview : Cannot view app documents images in app web view iOS swift