如何从uid查询用户详细信息?

时间:2016-08-13 20:41:51

标签: swift firebase firebase-authentication

我正在使用Firebase数据库查询"产品"。我也试图查询上传产品的用户的详细信息。我怎样才能做到这一点?

以下是用户上传产品的方式。 (我保存uid,因为他们上传):

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="75dp"
    android:divider="@android:color/transparent"
    android:dividerHeight="15dp">
<android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        card_view:cardCornerRadius="8dp"
        card_view:cardElevation="8dp"
        android:foreground="?android:attr/selectableItemBackground">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <TextView
            android:textAppearance=
                "?android:attr/textAppearanceMedium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="12dp"
            android:id="@+id/item_flow_name" />
        <!-- Flow Symbol Icon item_flow_name-->


        <ImageView
            android:contentDescription="@string/task_flag_description"
            android:id="@+id/item_element_icon"
            android:src="@drawable/flag_small_black_outline"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_marginEnd="125dp"
            android:layout_centerVertical="true"
            android:layout_alignParentEnd="true" />
            <!-- Insert Flow Element Icon -->

        <TextView
            android:id="@+id/item_element_count"
            android:textAppearance=
                "?android:attr/textAppearanceSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignLeft="@+id/item_element_icon"
            android:layout_marginLeft="25dp" />

        <ImageView
            android:contentDescription="@string/timer_description"
            android:id="@+id/item_time_icon"
            android:src="@drawable/timer_black_48dp"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_centerVertical="true"
            android:layout_alignStart="@+id/item_element_icon"
            android:layout_toRightOf="@+id/item_element_icon"
            android:layout_marginLeft="55dp" />
        <!-- Insert Flow Element Icon -->

        <TextView
            android:id="@+id/item_total_time"
            android:textAppearance=
                "?android:attr/textAppearanceSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignLeft="@+id/item_time_icon"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="2dp" />

        <TextView
            android:id="@+id/item_time_units"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/item_time_icon"
            android:layout_marginLeft="50dp"
            android:layout_alignLeft="@+id/item_time_icon"
            android:layout_marginTop="2dp" />
        </RelativeLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

以下是我查询产品的方法:

    let imageData = UIImageJPEGRepresentation(self.productImage.image!, 0.4)


    self.productImg = UIImage(data: imageData!)!



    let productImgData = UIImageJPEGRepresentation(productImg, 0.4)


    let storageRef = FIRStorage.storage().reference()
    let databaseRef = FIRDatabase.database().reference()
    let uid = FIRAuth.auth()?.currentUser?.uid


    let productImageRef = storageRef.child("ProductImages/\(uid!)/productImage.jpg")
    productImageRef.putData(productImgData!, metadata: nil) {
        metadata, error in

        if error != nil {

            print("Error occurred!")

        } else {


            let downloadURL = metadata?.downloadURL()?.absoluteString
            let post : [NSObject : AnyObject] = ["uid" : uid!,
                        "productTitle" : self.titleLabel.text!,
                        "price" : self.priceLabel.text!,
                        "description" : self.descriptionLabel.text!,
                        "productImage" : downloadURL!]

          databaseRef.child("Products").childByAutoId().setValue(post)


        }

基本上,如何根据用户的uid查询username / profileImage?

enter image description here

0 个答案:

没有答案