【问题标题】:Firebase retrieve user image with user IDFirebase 使用用户 ID 检索用户图像
【发布时间】:2016-05-25 17:45:29
【问题描述】:

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

        }

    }




}

【问题讨论】:

    标签: ios swift firebase firebase-authentication


    【解决方案1】:

    需要更多有关 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
    })
    

    希望对您有所帮助!

    【讨论】:

    • 像这样您无法看到其他用户配置文件,因为您不知道 UID。
    最近更新 更多