将用户个人资料图片保存到Firebase

时间:2018-07-02 06:07:29

标签: swift firebase uiviewcontroller uiimagepickercontroller firebase-storage

下午好,我正在尝试允许用户将其个人资料图片保存在Firebase中。我的应用程序运行时没有崩溃。但是,当我选择图片时,它不会保存到系统中。我有一个ViewController和一个扩展文件,我一直在其中放置代码。我将在下面放置。请帮助我了解我在做什么错。希望这个问题能对面临同样问题的其他人有所帮助。

var th = [] <==== chnage Var to var
th.push("");
if(th.includes($("#multiselect").val())) { <=== you can use includes method of array
    // DO whatever you want
}

//这是我的扩展文件

import UIKit
import Firebase

class EditProfileVC: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    setupProfileImageView()
    self.view.backgroundColor = UIColor.white

}
func setupProfileImageView() {
    view.addSubview(profileImageView)
    profileImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    profileImageView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 100).isActive=true
    profileImageView.widthAnchor.constraint(equalToConstant: 120).isActive = true
    profileImageView.heightAnchor.constraint(equalToConstant: 120).isActive = true
    profileImageView.layer.cornerRadius = 60
    profileImageView.layer.masksToBounds = true
   var randomString = UUID().uuidString
    let storageRef = Storage.storage().reference().child;"\(randomString).png")

    if let uploadImage = UIImagePNGRepresentation(self.profileImageView.image!) {

        storageRef.putData(uploadImage, metadata: nil) { (metadata, error) in
            if error != nil {
                print("Error upload data to Firebase Storage. Detail: \(String(describing: error))")
                return
            }
            if let profileImageURl = metadata?.downloadURL()?.absoluteString {
            self.registerUser(UserId: userId, profileImageURL: profileImageURL) {
            }
        }
    }
    }

}
lazy var profileImageView: UIImageView = {
    let imageView = UIImageView()
    imageView.image = UIImage(named: "users")
    imageView.translatesAutoresizingMaskIntoConstraints = false
    imageView.contentMode = .scaleAspectFill

    imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectProfileImageView)))
    imageView.isUserInteractionEnabled = true
    return imageView
}()

}

我的应用程序在运行时不会崩溃。只是没有图像存储在Firebase中。我希望用户单击EditProfileVC,然后能够更改其个人资料图片并将其保存。如果有人可以帮助我解决此问题,将不胜感激。

0 个答案:

没有答案