ios - Firebase 使用用户 ID 检索用户图像

标签 ios swift firebase firebase-authentication

我目前有此功能来检索当前用户图像图像 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/

相关文章:

java - 如何在亚马逊应用商店发布 Firebase 登录应用程序?

ios - 在 Swift 中定义协议(protocol)

ios - 从另一个类中的 UITextField 访问文本

ios - swift 数组在循环时不追加

ios - NSPersistentContainer 不创建数据库文件

javascript - 如何防止 Firebase 实时数据库、Web、JavaScript 的数据重复

ios - 访问钥匙串(keychain)时出错

ios - OpenGL ES 2.0,使用多个顶点缓冲区进行绘制

iphone - NSIncrementalStore - 使用本地和远程数据

ios - captureStillImageAsynchronously 在特定时间不起作用