How to link Firebase download file with a progress view?

一笑奈何 提交于 2019-12-03 21:25:57

Several thoughts:

Putting that together, you get something like:

// Create a reference to the file we want to download
let starsRef = storageRef.child("images/stars.jpg")

// Start the download (in this case writing to a file)
let downloadTask = storageRef.write(toFile: localURL)

// Start progress indicator

// Observe changes in status
downloadTask.observe(.progress) { snapshot in
  // Download reported progress
  let percentComplete = 100.0 * Double(snapshot.progress!.completedUnitCount)
    / Double(snapshot.progress!.totalUnitCount)
  // Update the progress indicator
}

downloadTask.observe(.success) { snapshot in
  // Download completed successfully
  // Stop progress indicator
}

// Errors only occur in the "Failure" case
downloadTask.observe(.failure) { snapshot in
  // An error occurred!
  // Stop progress indicator
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!