У меня проблема с xcode из учебной сессии - PullRequest
0 голосов
/ 03 октября 2018

У меня есть код, который я хотел бы, чтобы кто-нибудь проверил для меня.По-видимому, он не работает из-за синтаксиса Firebase 4, но у меня нет опыта по обновлению до 5. Я следую учебному пособию, но оно также и в 4, и репетитор не отвечает на вопрос.Основная цель кода - иметь возможность вручную выбрать изображение для импорта в качестве изображения профиля, а затем загрузить его в мое хранилище Firebase.Пожалуйста, если кто-то может помочь, я был бы очень признателен.

import UIKit
import FirebaseAuth
import FirebaseDatabase
import FirebaseStorage
class SignUpViewController: UIViewController {
    @IBOutlet weak var usernameTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    @IBOutlet weak var emailTextField: UITextField!

    @IBOutlet weak var profileImage: UIImageView!

    var selectedImage: UIImage?

    override func viewDidLoad() {
        super.viewDidLoad()

       usernameTextField.backgroundColor = UIColor.clear
    usernameTextField.tintColor = UIColor.white
    usernameTextField.textColor = UIColor.white
    usernameTextField.attributedPlaceholder = NSAttributedString(string: usernameTextField.placeholder!, attributes: [NSAttributedStringKey.foregroundColor: UIColor(white: 1.0, alpha: 0.6)])
    let bottomLayerUsername = CALayer()
    bottomLayerUsername.frame = CGRect(x: 0, y: 29, width: 1000, height: 0.6)
    bottomLayerUsername.backgroundColor = UIColor(red: 50/255, green: 50/255, blue: 25/255, alpha: 1).cgColor
    usernameTextField.layer.addSublayer(bottomLayerUsername)

    emailTextField.backgroundColor = UIColor.clear
    emailTextField.tintColor = UIColor.white
    emailTextField.textColor = UIColor.white
    emailTextField.attributedPlaceholder = NSAttributedString(string: emailTextField.placeholder!, attributes: [NSAttributedStringKey.foregroundColor: UIColor(white: 1.0, alpha: 0.6)])
    let bottomLayerEmail = CALayer()
    bottomLayerEmail.frame = CGRect(x: 0, y: 29, width: 1000, height: 0.6)
    bottomLayerEmail.backgroundColor = UIColor(red: 50/255, green: 50/255, blue: 25/255, alpha: 1).cgColor
    emailTextField.layer.addSublayer(bottomLayerEmail)

    passwordTextField.backgroundColor = UIColor.clear
    passwordTextField.tintColor = UIColor.white
    passwordTextField.textColor = UIColor.white
    passwordTextField.attributedPlaceholder = NSAttributedString(string: passwordTextField.placeholder!, attributes: [NSAttributedStringKey.foregroundColor: UIColor(white: 1.0, alpha: 0.6)])
    let bottomLayerPassword = CALayer()
    bottomLayerPassword.frame = CGRect(x: 0, y: 29, width: 1000, height: 0.6)
    bottomLayerPassword.backgroundColor = UIColor(red: 50/255, green: 50/255, blue: 25/255, alpha: 1).cgColor
    passwordTextField.layer.addSublayer(bottomLayerPassword)


        profileImage.layer.cornerRadius = 40
        profileImage.clipsToBounds = true

        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(SignUpViewController.handleSelectProfileImageView))
        profileImage.addGestureRecognizer(tapGesture)
        profileImage.isUserInteractionEnabled = true
    }

    func handleSelectProfileImageView() {
        let pickerController = UIImagePickerController()
        pickerController.delegate = self
        present(pickerController, animated: true, completion: nil)
    }
    @IBAction func dismiss_onClick(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }

    @IBAction func signUpBtn_TouchUpInside(_ sender: Any) {
        Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: { (authData: AuthDataResult?, error: Error?) in
            if error != nil {
                print(error!.localizedDescription)
                return
            }
            let uid = authData!.user.uid
            let storageRef = Storage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("profile_image").child(uid)
            if let profileImg = self.selectedImage, let imageData = UIImageJPEGRepresentation(profileImg, 0.1) {
               storageRef.put(imageData, metadata: nil, completion: { (metadata, error) in
                if error != nil {
                    return
                }

                let profileImageUrl = metadata?.downloadURL()?.absoluteString
                let ref = Database.database().reference()
                let usersReference = ref.child("users")
                let newUserReference = usersReference.child(uid!)
                newUserReference.setValue(["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "profileImageUrl": profileImageUrl])
               })
            }
        })
...