【发布时间】:2021-01-25 20:34:27
【问题描述】:
下载文件有问题。
我正在尝试下载文件表单 url 并将其推送到打开/共享模式。但是 da 数据作为数据下载,如果我尝试将其保存到文件应用程序,它会保存一个名为数据的文件。
我只需要下载并共享带有原始扩展名的文件。喜欢 file.extension。
这里是代码使用。我在这里使用了 Alamofire pod:
AF.download(url).responseData { response in
if let preset = response.value {
let shareArray = [preset]
let activityViewController = UIActivityViewController(activityItems: shareArray , applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
}
}
也试过这段代码,但应用崩溃了:
if let url = URL(string: downloadURL!) {
let task = URLSession.shared.downloadTask(with: url) { localURL, urlResponse, error in
if let localURL = localURL {
let shareArray = [localURL]
let activityViewController = UIActivityViewController(activityItems: shareArray , applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
}
}
task.resume()
}
【问题讨论】:
标签: ios swift uitableview alamofire