admin管理员组文章数量:1122832
I am creating an iOS application in Swift. Downloading does not start when the “Download” button is pressed.
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate, WKDownloadDelegate {
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let configuration = WKWebViewConfiguration()
webView = WKWebView(frame: self.view.bounds, configuration: configuration)
webView.navigationDelegate = self
webView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(webView)
NSLayoutConstraint.activate([
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
webView.topAnchor.constraint(equalTo: view.topAnchor),
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
if let driveURL = URL(string: "GOOGLEDRIVE_FILE_URL") {
let request = URLRequest(url: driveURL)
webView.load(request)
}
}
func webView(_ webView: WKWebView, navigationResponse: WKNavigationResponse, didBecome download: WKDownload) {
download.delegate = self
print("download has started")
}
func download(_ download: WKDownload, decideDestinationUsing response: URLResponse, suggestedFilename: String, completionHandler: @escaping (URL?) -> Void) {
let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let destinationURL = documentsPath.appendingPathComponent(suggestedFilename)
completionHandler(destinationURL)
print("file save location: \(destinationURL)")
}
func downloadDidFinish(_ download: WKDownload) {
print("Download is complete")
}
func download(_ download: WKDownload, didFailWithError error: Error, resumeData: Data?) {
print("download error: \(error.localizedDescription)")
}
}
If it seems impossible, I am thinking of using URLSession to get it or using the API. Also, is it still ok to download by direct URL?
本文标签: iosI want to download files stored in Google Drive on WKWebViewStack Overflow
版权声明:本文标题:ios - I want to download files stored in Google Drive on WKWebView - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306926a1933134.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论