【发布时间】:2019-06-15 08:43:36
【问题描述】:
我正在创建一个基本的注册和登录页面应用程序,当用户成功注册或登录后,它会转到主屏幕。这是我的代码:
这是我调用按钮按下功能的地方
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}})
}
}
}
}
问题是,当我按下按钮时,没有任何效果。希望有人能帮帮我,谢谢!
【问题讨论】:
-
你在另一个方法中有一个方法,但你没有调用 func createUser。
标签: ios swift firebase firebase-authentication