ios - 使用 uid 从 firebase 下载图像

标签 ios swift firebase-realtime-database firebase-storage

我想在我的 tableview 中用户姓名旁边显示个人资料图像。

我已将图像上传到 Firebase 存储,并将图像 URL 存储在 Firebase 数据库中。一切都很完美。 个人资料图像上传到 firebase 存储中,URL 保存在数据库中,但下载代码时出现问题,因为当我运行应用程序时,个人资料图像没有出现。我没有从 Xcode 收到任何错误。

if let profileImageUrl = user.profileImageUrl{
        let url = URL(string: profileImageUrl)
        URLSession.shared.dataTask(with: url!,
            completionHandler:
            {(data, response, error) in

                //download hit error
                if error != nil {
                    print(error)
                    return
                }

                DispatchQueue.main.async() {
                    cell?.imageView?.image = UIImage(data: data!)
                }
        }).resume()
    }
    return cell!
}

最佳答案

您可以使用SDWebImageView来做到这一点

import SDWebImage

cell?.imageView?.sd_setImage(with: URL(string: user.profileImageUrl), placeholderImage: UIImage(named: "placeholder.png"))

关于ios - 使用 uid 从 firebase 下载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47860241/

相关文章:

android - FirebaseListAdapter 空 View

android - 为什么 Firebase 在明确更改设备的本地日期时停止同步?

ios - 如何从文件目录保存和加载图像 - Swift 4

ios - 尝试在 Swift 中将 Firebase 时间戳转换为 NSDate

ios - SKLabelNode 延迟应用程序启动

php - 验证 appReceiptStoreURL 返回 21002 状态

java - 字段未出现在 Firebase Android Studio 的数据库中

ios - 使用 Alamofire responseImage IOS swift 从 URLRequest 加载图像

ios - Swift 中泛型关联类型的比较类型

ios - swift 地,我如何以编程方式制作 View 层?