I have been downloading zip file from server and extracting the zip file in local directory.
ie, /var/mobile/Containers/Data/Application/8A7B8DF1-AAA4-442E-99C9-82616FC3E192/Documents/assets.zip
Unzip path: /var/mobile/Containers/Data/Application/8A7B8DF1-AAA4-442E-99C9-82616FC3E192/Library/Caches/47B7913E-A0B2-429D-AD91-AA3367EFB2AE
From unzipped folder, i need to load index.html to WkWebView. But i could able to find folder but not able load into webview.
here is code for download zip file and extracting zip file in local directory:
let url = URL(string: v)
FileDownloader.loadFileAsync(url: url!) { (path, error) in
print("PDF File downloaded to : \(path!)")
guard let unzipPath = self.tempUnzipPath() else {
return
}
print("Unzip path:", unzipPath)
let success: Bool = SSZipArchive.unzipFile(atPath: path!,
toDestination: unzipPath,
preserveAttributes: true,
overwrite: true,
nestedZipLevel: 1,
password: nil,
error: nil,
delegate: nil,
progressHandler: nil,
completionHandler: nil)
if success != false {
print("Success unzip")
} else {
print("No success unzip")
return
}
var items: [String]
do {
items = try FileManager.default.contentsOfDirectory(atPath: unzipPath)
print("array item for unzip", items[0])
} catch {
return
}
for v in items[0] {
print("vv index.html", v)
self.buildAry.append(v)
}
print("build ary", self.buildAry)
let ss = self.buildAry[0]
print("index html", ss)
}
here is my console output:
Success unzip
array item for unzip build
vv index.html b
vv index.html u
vv index.html i
vv index.html l
vv index.html d
build ary 2020-02-07 19:40:44.480754+0530[9847:2135988] [Process] kill() returned unexpected error 1
["b", "u", "i", "l", "d"]
index html b
How to load index.html into WKWebView from unzipped folder. Any help much appreciated pls..
Generally to open a local file in WKWebView you can call loadFileURL(URL, allowReadAccessTo: URL)
on your WKWebView instance.
Edit after your comment:
If you know, that your index.html will always be in „build“ folder you can do:
let url = URL(fileURLWithPath: unzipPath, isDirectory: false).appendingPathComponent("build").appendindPathComponent("Index.html", isDirectory: false)
myWKWebView.loadFileURL(url, allowsReadAccessTo: url)
If you need more help, please comment.