我想从firebase存储中下载图像并将其加载到tableview中,但它无法正常工作。
我的downloadUrl
是正确的,没有错误。
URLSession.shared.dataTask(with: downloadURL) { (data, response, error) in
if error != nil {
print(error?.localizedDescription)
return
}
DispatchQueue.main.async {
if let downloadedImage = UIImage(data: data!) {
cell.imageView?.image = downloadedImage
}
}
}
答案 0 :(得分:0)
为什么不直接使用Firebase Storage built in download mechanisms?
let httpsReference = FIRStorage.storage().referenceForURL('https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg') // your download URL
httpsReference.dataWithMaxSize(1 * 1024 * 1024) { (data, error) -> Void in
if (error != nil) {
// Uh-oh, an error occurred!
} else {
// Data for "images/stars.jpg" is returned
let starsImage: UIImage! = UIImage(data: data!)
cell.imageView.image = starsImage // by default, callbacks are raised on the main thread so this will work
}
}