尝试创建帐户时出现致命错误

时间:2019-05-06 13:05:36

标签: swift xcode

我遵循了YouTube上的聊天应用程序教程,但是在尝试创建帐户时遇到致命错误。它在“ metadata.downloadURL”方面存在一些问题,但我想我可以使用storageRef来解决此问题,但是单击控制台中的CreateAccount按钮时仍然出现错误:在发现扩展时遇到[发现]错误:错误域= PlugInKit代码= 13“查询已取消” UserInfo = {NSLocalizedDescription =查询已取消}

func uploadImg() {
        if usernameField.text == nil {
            signUpBtn.isEnabled = false
        } else {
            username = usernameField.text
            signUpBtn.isEnabled = true

        }

        guard let img = userImagePicker.image, imageSelected == true else {
            print("image needs to be selected")

            return
        }

        if let imgData = img.jpegData(compressionQuality: 0.8) {

            let imgUid = NSUUID().uuidString

            let metadata = StorageMetadata()

            metadata.contentType = "image/jpg"

            let storageRef = Storage.storage().reference().child(imgUid)

            storageRef.putData(imgData, metadata: metadata) { (metadata, error) in
                if error != nil {
                    print("did not upload img")
                }else {
                    print("uploaded")
                    storageRef.downloadURL(completion: { (url, error) in
                        if (error == nil) {
                            if let downloadUrl = url {
                                // Make you download string
                                let downloadString = downloadUrl.absoluteString
                                self.setUser(img: downloadString)
                            }
                        } else {
                            // Do something if error
                        }
                    })

                }

            }
        }

    }

    @objc @IBAction func createAccount(_ sender: AnyObject){
        Auth.auth().createUser(withEmail: emailField, password: passwordField,
            completion: {(user,error) in

            if error != nil{

                print("Cant create user")

            }else {
                if let user = user {
                    self.userUid = user.user.uid
                }
            }
            self.uploadImg()
        })
    }

    @IBAction func seletedImgPicker (_ sender: AnyObject){
        present(imagePicker, animated: true, completion: nil)
    }

    @IBAction func cancel(_ sender: AnyObject){
        dismiss(animated: true, completion: nil)
    }

0 个答案:

没有答案