使用uid

时间:2017-12-17 22:53:01

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

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

我已将我的图片上传到Firebase存储空间,并将图片网址存储在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!
}

2 个答案:

答案 0 :(得分:0)

You can do this by using SDWebImageView

import SDWebImage

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

答案 1 :(得分:0)

A piece of advice. Use Glide for downloading the pictures. It is as easy as :

Glide.with(ExampleActivity).load(url).into(imageView);