【问题标题】:Firebase ios manage download with FirebaseUIFirebase ios 使用 FirebaseUI 管理下载
【发布时间】:2018-06-05 05:12:50
【问题描述】:

如果我使用FirebaseUI 下载图像,我们可以管理(暂停、停止或恢复)下载吗?如果我需要进步,我能得到进步吗?我的主要问题是,有没有办法使用FirebaseUI 将下载作为任务来管理?

【问题讨论】:

    标签: ios firebase firebase-storage firebaseui swift4.1


    【解决方案1】:

    您检查过https://firebase.google.com/docs/storage/ios/download-files 吗?它包含有关如何使用 FirebaseUI 管理下载甚至获取进度的示例。

    管理下载 除了开始下载之外,您还可以使用 pause、resume 和 cancel 方法暂停、恢复和取消下载。这些方法引发了您可以观察到的暂停、恢复和取消事件。

    // Start downloading a file
    let downloadTask = storageRef.child("images/mountains.jpg").write(toFile: localFile)
    
    // Pause the download
    downloadTask.pause()
    
    // Resume the download
    downloadTask.resume()
    
    // Cancel the download
    downloadTask.cancel()
    

    监控下载进度 您可以将观察者附加到 FIRStorageDownloadTasks 以监控下载进度。添加观察者会返回一个 FIRStorageHandle,可用于移除观察者。

    // Add a progress observer to a download task
    let observer = downloadTask.observe(.progress) { snapshot in
      // A progress event occurred
    }
    

    【讨论】:

    • 在 FirebaseUI 中无需创建任务。只需将参考并将图像设置为 imageview。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 2017-01-19
    • 2016-01-06
    • 2021-11-05
    • 2018-06-10
    • 2017-05-04
    相关资源
    最近更新 更多