2016-05-25 5 views
0

私は現在、現在のユーザイメージイメージのURLを取得するためにこの機能を持っていますが、私はcurrentUserの代わりにユーザIDを使用します。すべては、コードでうまく動作しますが、私はちょうどあなたのFirebaseデータの構造についての詳しい情報は、完全な答えを与える必要があるFirebaseはユーザIDを持つユーザイメージを取得します

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!) 

     } 

    } 




} 

答えて

2

また、他のユーザーに機能を使用できるようにしたいが、私は右にあなたを導くことができますパス。

ユーザーが固有の識別子をキーとして格納されている場合は、この参照を使用してプロフィール画像の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 
}) 

希望はこれです。

+0

このように、あなたはUIDを知らないので他のユーザープロフィールを見ることができません。 –

関連する問題