var image = WKWebView()
var link:String!
func down(){
//指定下载路径和保存文件名
var z:URL = URL(string:link)!
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentsURL.appendingPathComponent("file1/\(self.link)")
z = fileURL
//两个参数表示如果有同名文件则会覆盖,如果路径中文件夹不存在则会自动创建
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
//开始下载
Alamofire.download(link, to: destination)
.downloadProgress { progress in
SVProgressHUD.showProgress(Float(progress.completedUnitCount/progress.totalUnitCount), status: "正在下载")
print("已下载:\(progress.completedUnitCount/1024)KB")
print("总大小:\(progress.totalUnitCount/1024)KB")
}
.responseData { response in
if let data = response.result.value {
print("下载完毕!")
SVProgressHUD.dismiss()
let image2 = UIImage(data: data)
DispatchQueue.main.async {
if let path = response.destinationURL?.path{
let urlStr = URL.init(fileURLWithPath:path);
let data = try! Data(contentsOf: urlStr)
self.image.load(data, mimeType: "application/pdf", characterEncodingName: "utf-8", baseURL: NSURL() as URL)
}
}
}
}
}
swift 使用WKWebView加载网络PDF
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。