简体   繁体   English

用户uid错误! (Swift和Firebase项目)

[英]The user uid error! (Swift and Firebase Project)

I'm working on iOS application using swift and firebase. 我正在使用swift和firebase开发iOS应用程序。

I'm having a view called add device, where the registered user can add a device. 我有一个称为添加设备的视图,注册用户可以在其中添加设备。 Simply he/she can enter the device name, description, category and add the image then click on add device button. 他/她只需输入设备名称,描述,类别并添加图像,然后单击添加设备按钮即可。

Here's the current dashboard that contains the info of the registered users: 这是当前的仪表板,其中包含注册用户的信息:

{
"UserProfile" : {
"1EJ8QmEQBJfBez7PMADbftCjVff1" : {
  "city" : "الرياض",
  "email" : "noura@gmail.com",
  "name" : "Norah",
  "phone" : "0564695353"
},
"97PUAcUC5UYxLpBOLnC4yQjxiEf2" : {
  "city" : "Riyadh",
  "email" : "mawada2017@gmail.com",
  "name" : "Mawada",
  "phone" : "0534260282"
  }
 }
}

I want to add the device info into another node. 我想将设备信息添加到另一个节点。

Here's the button: 这是按钮:

     @IBAction func AddDeviceButton(sender: AnyObject) {

    if DeviceName.text == "" || Description.text == "" || ImageView.image == nil {
        let alert = UIAlertController(title: "عذرًا", message:"يجب عليك تعبئة معلومات الجهاز كاملة", preferredStyle: .Alert)
        alert.addAction(UIAlertAction(title: "نعم", style: .Default) { _ in })
        self.presentViewController(alert, animated: true){}

    } else {


        let imageName = NSUUID().UUIDString
        let storageRef = FIRStorage.storage().reference().child("Devices_images").child("\(imageName).png")

        if let uploadData = UIImagePNGRepresentation(self.ImageView.image!) {

            storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in

                if error != nil {
                    print(error)
                 return
                }

                let profileImageUrl = metadata?.downloadURL()?.absoluteString

                 let DeviceInfo = [
                        "ImageUrl":profileImageUrl!,
                        "DeviceName":self.DeviceName.text!,
                        "Description":self.Description.text!,
                        "Category":self.itemSelected
                        ]

                    self.ref.child("Devices").child(user!.uid).setValue(DeviceInfo)

            })






}

}

In this line: 在这一行:

  self.ref.child("Devices").child(user!.uid).setValue(DeviceInfo)

The view could not recognize the uid! 视图无法识别uid!

Why? 为什么?

Just replace 只需更换

self.ref.child("Devices").child(user!.uid).setValue(DeviceInfo)

with

self.ref.child("Devices").child(FIRAuth.auth()!.currentUser!.uid).setValue(DeviceInfo)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM