我希望一切顺利, 请问我从firebase下载用户的图像配置文件有问题,当我想从firebase中获取当前用户的信息时,包含图片网址和名称我得到的是nil, 我使用URLSession下载图像配置文件,我成功地从会话接收图像的数据,但只有当我从会话中收到的数据创建图像时我得到的图像为零,我无法更新图像视图在主线程中,请问我该如何解决这个问题,
以下我的代码:
private func loadUserData() {
if let user = FIRAuth.auth()?.currentUser {
guard let _ = user.displayName else {
print("Not Have User Name")
return
}
guard let PhotoURL = user.photoURL else {
print("Have No Image")
return
}
// if have the image so we can download it from the fire base
URLSession.shared.dataTask(with: PhotoURL, completionHandler: { (data:Data?, response:URLResponse?, error:Error?) in
if let error = error {
self.showAlert(title: "Error", message: error.localizedDescription)
}else{
if let fetchData = data , let image = UIImage(data: fetchData) {
DispatchQueue.main.async {
self.imageView.image = image
}
}else{
print("image nil")
}
}
}).resume()
}
}