我试图创建一个登录/注册通过警报弹出一旦登录或注册按钮被点击。我正在尝试将它实现到Firebase 4中。到目前为止,我已经完成了这一任务,但是我还在研究如何实现Firebase。我读过他们的文档,但我似乎无法让alertView正常工作。有什么建议吗?
import UIKit
import Firebase
class welcomeController: UIViewController {
alertController.addTextFieldWithConfigurationHandler { textField in
textField.placeholder = "Email"
textField.keyboardType = .EmailAddress
}
alertController.addTextFieldWithConfigurationHandler { textField in
textField.placeholder = "Password"
textField.secureTextEntry = true
}
alertController.addTextFieldWithConfigurationHandler { textField in
textField.placeholder = "Password Confirmation"
textField.secureTextEntry = true
}
alertController.addAction(loginAction)
alertController.addAction(forgotPasswordAction)
alertController.addAction(cancelAction)
}发布于 2018-02-09 14:16:29
请参考以下代码。为了演示登录和注册,我增加了登录和注册的操作。为了更好地理解,我已经在登录和注册操作中提到了重复的代码。这段代码只是为了你的理解。
let alertController = UIAlertController(title: nil, message: "Login/Signup", preferredStyle: .alert)
alertController.addTextField { (textField) in
textField.placeholder = "Email"
textField.keyboardType = .emailAddress
}
alertController.addTextField { (textField) in
textField.placeholder = "Password"
textField.isSecureTextEntry = true
}
alertController.addTextField { (textField) in
textField.placeholder = "Password Confirmation"
textField.isSecureTextEntry = true
}
let loginAction = UIAlertAction(title: "Login", style: .default) { (_) in
let emailField = alertController.textFields![0]
let passwordField = alertController.textFields![1]
let conformPasswordField = alertController.textFields![2]
//Perform validation or whatever you do want with the text of textfield
//Login With Firebase
Auth.auth().signIn(withEmail: emailField.text!, password: passwordField.text!) { (user, error) in
// ...
}
}
let signupAction = UIAlertAction(title: "Signup", style: .default) { (_) in
let emailField = alertController.textFields![0]
let passwordField = alertController.textFields![1]
let conformPasswordField = alertController.textFields![2]
//Perform validation or whatever you do want with the text of textfield
//SigunUp With Firebase
Auth.auth().createUser(withEmail: emailField.text!, password: passwordField.text!) { (user, error) in
// ...
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(loginAction)
alertController.addAction(signupAction)
alertController.addAction(cancelAction)
DispatchQueue.main.async {
self.present(alertController, animated: true, completion: nil)
}要了解有关firebase身份验证和登录/注册过程的更多信息,请参考以下链接:https://firebase.google.com/docs/auth/ios/password-auth
发布于 2018-02-09 13:48:54
处理操作处理程序中的事件,例如:
let loginAction = UIAlertAction(title: "SIGN UP", style: .default) { (action) in
guard let textFields = alertController.textFields else { return } //show error
let email = textFields[0].text
let password = textFields[1].text
let cPassword = textFields[2].text
print(email, password, cPassword)
}https://stackoverflow.com/questions/48707059
复制相似问题