繁体   English   中英

在 swift 中使用 Alamofire 从 Firebase 存储下载文件

[英]Download file from Firebase Storage using Alamofire in swift

我是 iOS 开发的新手。 所以我正在尝试使用 Alamofire 从带有 URL 的 firebase 存储下载 pdf 或图像,然后我想用 quicklook 显示。 我试过这个例子,但没有运气。 直接在应用程序中显示下载文件的预览

import UIKit
import Alamofire
import QuickLook

class DocumentViewer: UIViewController{
    var previewItem = URL?.self
    var refrenceDocURL: URL? // here i get the url from another view controller but never use it because I don't know where should I use it.
    
    func downloadFile(fileUrl: URL) {
        let destination: DownloadRequest.DownloadFileDestination = { _, _ in //ERROR: 'DownloadFileDestination' is not a member type of class 'Alamofire.DownloadRequest'
            let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
            let fileURL = documentsURL.appendingPathComponent(documentFilename)
            return (fileURL, [.removePreviousFile])
        }

        Alamofire.download(fileUrl, to: destination)   //ERROR: Module 'Alamofire' has no member named 'download'
            .response(completionHandler: { (downloadResponse) in

              let previewController = QLPreviewController()
              previewController.dataSource = self
              self.previewItem = downloadResponse.destinationURL
              self.present(previewController, animated: true, completion: nil)
          })
        }
      }

extension DocumentViewer: QLPreviewControllerDataSource {
    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
        return 1
    }

    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
       return self.previewItem as! QLPreviewItem
    }
}

这是错误的屏幕截图

看起来您正在使用旧定义。

DownloadRequest.DownloadFileDestinationDownloadRequest.Destination

Alamofire.downloadAF.download

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM