我目前有此功能来检索当前用户图像图像 url,但我想使用用户 ID 而不是 currentUser 如何做到这一点。一切都适用于代码,但我只想能够在其他用户身上使用该功能
func ProfileImage(imageUIView:UIImageView,borderColor:UIColor,borderWidth:CGFloat,backgroundColor:UIColor,noimageLabel:UILabel){
if let user = FIRAuth.auth()?.currentUser{
if user.photoURL == ""{
print("database image is not set")
imageUIView.layer.borderWidth = borderWidth
imageUIView.layer.masksToBounds = false
imageUIView.layer.borderColor = borderColor.CGColor
imageUIView.layer.cornerRadius = imageUIView.frame.height/2
imageUIView.clipsToBounds = true
imageUIView.backgroundColor = backgroundColor
noimageLabel.hidden = false
}else{
imageUIView.layer.borderWidth = borderWidth
imageUIView.layer.masksToBounds = false
imageUIView.layer.borderColor = borderColor.CGColor
imageUIView.layer.cornerRadius = imageUIView.frame.height/2
imageUIView.clipsToBounds = true
imageUIView.backgroundColor = backgroundColor
noimageLabel.hidden = true
var imageUrl = NSData(contentsOfURL: user.photoURL!)
imageUIView.image = UIImage(data: imageUrl!)
}
}
}
最佳答案
关于您的 Firebase 数据结构的更多信息对于给出完整的答案是必要的,但我可以指导您走上正确的道路。
只要您的用户存储了唯一标识符作为他们的键,您就可以使用此引用来检索他们的个人资料图片的 url。
var userRef = FIRDatabase.database().reference().child(<url to user ids> + "\(unique user id)") // this creates a FIRDatabase ref to the specified user id
userRef.observeSingleEventOfType(.Value, :withBlock: { (snapshot)
// perform desired functionallity with the image URL from the specified user
})
希望对您有所帮助!
关于ios - Firebase 使用用户 ID 检索用户图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37444286/