Advertisement
Guest User

Firebase Problem

a guest
Dec 2nd, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.86 KB | None | 0 0
  1.  @objc func handleSignup(){
  2.         guard let email = emailTextField.text, email.count > 0 else { return }
  3.         guard let password = paswordTextField.text, password.count > 0 else { return }
  4.         guard let username = usernameTextField.text, username.count > 0 else { return }
  5.        
  6.         Auth.auth().createUser(withEmail: email, password: password) { (user, err) in
  7.             if let error = err{
  8.                 print("Failed to create the user", error.localizedDescription)
  9.                 return
  10.             }
  11.             print("The user is successfully created ", user?.user.uid ?? "")
  12.            
  13.             guard let image = self.buttonView.imageView?.image else{ return }
  14.            
  15.             guard let uploadData = image.jpegData(compressionQuality: 0.3) else { return }
  16.            
  17.             let uuid = NSUUID().uuidString
  18.            
  19.             print("The uuid is \(uuid)")
  20.             print("Coming to here ")
  21.             Storage.storage().reference().child("profileImages").child(uuid).putData(uploadData, metadata: nil, completion: { (metadata, error) in
  22.                
  23.                 if let error = error{
  24.                     print("Failed to upload image with \(error.localizedDescription)")
  25.                     return
  26.                 }
  27.                
  28.                 if metadata != nil{
  29.                     Storage.storage().reference().child("profileImages").child(uuid).downloadURL(completion: { (url, err) in
  30.                         if let error = err{
  31.                             print("There is some error fetching the urls \(error.localizedDescription)")
  32.                         }
  33.                         guard let downloadurl = url?.absoluteString else { return }
  34.                         print("The fetched url is ", downloadurl)
  35.                     })
  36.                 }
  37.                
  38.             })
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement