Я создаю базовое приложение для регистрации и страницы входа, которое переходит на домашний экран, когда пользователь успешно зарегистрировался или вошел в систему. Вот мой код:
Здесь я вызываю нажатие кнопки.function
signupButton.addTarget(self, action: #selector(signupButtonPressed), for: .touchUpInside)
Это код для создания пользователя и сохранения в базе данных.
@objc func signupButtonPressed() {
// Check that the text fields aren't empty
if let username = username.text, let password = password.text, let email = email.text, let country = countryTextField.text {
// Create a user
func createUser(withEmail email: String, username: String, password: String, country: String) {
// Sign up user only if all the text fields are filled
Auth.auth() .createUser(withEmail: email, password: password) { (result, error) in
if result != nil {
// User found, go to main page
let mainPage = MainScreen()
self.present(mainPage, animated: true, completion: nil)
} else {
// Error: show error message
print("Failed to sign user up with error: ", error!.localizedDescription)
return
}
guard let userID = result?.user.uid else {return}
let values = ["email": email, "username": username]
Database.database().reference().child("Users").child(userID).updateChildValues(values, withCompletionBlock: {(error, ref) in
if let error = error {
print("Failed to update database values with error: ", error.localizedDescription)
return}})
}
}
}
}
Проблема в том, что, когда я нажимаю кнопку, ничего не работает.Надеюсь, кто-нибудь может мне помочь, спасибо!