开发者社区> 问答> 正文

“StorageMetadata”类型的值没有成员“downloadURL”

嘿,我需要这个编码的帮助,我不知道发生了什么。前几天起作用了。错误出现在if let ur; = metaData?.downladURL()

func uploadProfileImage(_ image:UIImage, completion: @escaping ((_ url:URL?)->())) {
        guard let uid = Auth.auth().currentUser?.uid else { return }
        let storageRef = Storage.storage().reference().child("user/\(uid)")

        guard let imageData = UIImageJPEGRepresentation(image, 0.75) else { return }

        let metaData = StorageMetadata()
        metaData.contentType = "image/jpg"

        storageRef.putData(imageData, metadata: metaData) { metaData, error in
            if error == nil, metaData != nil {
                if let url = metaData?.downloadURL() {
                    completion(url)
                } else {
                    completion(nil)
                }
                // success!
            } else {
                // failed
                completion(nil)
            }
        }
    }

展开
收起
游客5akardh5cojhg 2019-12-15 16:57:26 436 0
1 条回答
写回答
取消 提交回答
  • // MARK: - handleRegister
    func handleRegister() {
        guard let email = emailTextField.text, let password = passwordTextField.text, let name = nameTextField.text else {
            print("Error")
            return
        }
    
        Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
            if error != nil {
                // print("Error")
                return
            }
    
            // MARK: - hadleLogin// 
    
            guard let uid = Auth.auth().currentUser?.uid  else {
                return
            }
    
            // MARK: - image successful authenficated user
    
            let imageName = NSUUID().uuidString
            let storageRef = Storage.storage().reference().child("profile_images").child("\(imageName).png")
    
            if let profileImageUrl = self.profileImageView.image, let  uploadData = UIImageJPEGRepresentation(self.profileImageView.image!, 0.1) {
                storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
    
                    if error != nil, metadata != nil {
                        print(error ?? "")
                        return
    
                    }
    
                    storageRef.downloadURL(completion: { (url, error) in
                        if error != nil {
                            print(error!.localizedDescription)
                            return
                        }
                        if let profileImageUrl = url?.absoluteString {
                            let values = ["name": name, "email": email, "profileImageUrl": profileImageUrl]
                            self.registeUserIntoDatabaseWithUID(uid: uid, values: values as [String : AnyObject])
                        }
                    })
                })
            }
        }
    }
    
    2019-12-15 16:58:16
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载