One way to preserve the directory structure when uploading local files to the UIWebview on an iPhone is to use a file URL scheme.
First, get the local file path using a file manager:
let fileManager = FileManager.default
guard let filePath = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("myFolder/myFile.pdf") else {
return
}
Then, create a file URL with the path and load it into the webview:
let fileURL = URL(fileURLWithPath: filePath.absoluteString)
let request = URLRequest(url: fileURL)
webView.load(request)
This approach will preserve the directory structure of the file when loading it into the webview.
Asked: 2023-05-05 22:35:32 +0000
Seen: 10 times
Last updated: May 05 '23