【发布时间】:2020-05-23 16:48:14
【问题描述】:
我一直在从服务器下载 zip 文件并在本地目录中提取 zip 文件。
即,/var/mobile/Containers/Data/Application/8A7B8DF1-AAA4-442E-99C9-82616FC3E192/Documents/assets.zip
解压路径:/var/mobile/Containers/Data/Application/8A7B8DF1-AAA4-442E-99C9-82616FC3E192/Library/Caches/47B7913E-A0B2-429D-AD91-AA3367EFB2AE
从解压缩的文件夹中,我需要将 index.html 加载到 WkWebView。但我可以找到文件夹但无法加载到 webview。
这里是下载 zip 文件并在本地目录中提取 zip 文件的代码:
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)
}
这是我的控制台输出:
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
如何将 index.html 从解压文件夹加载到 WKWebView。非常感谢任何帮助..
【问题讨论】:
标签: ios swift webview zip wkwebview